mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 02:40:39 +09:00
Add plugin telemetry bridge capability
Expose telemetry.track through the plugin SDK and server host bridge, forward plugin-prefixed events into the shared telemetry client, and demonstrate the capability in the kitchen sink example.\n\nCo-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
53dbcd185e
commit
af844b778e
14 changed files with 209 additions and 1 deletions
|
|
@ -34,6 +34,7 @@ import { request as httpRequest } from "node:http";
|
|||
import { request as httpsRequest } from "node:https";
|
||||
import { isIP } from "node:net";
|
||||
import { logger } from "../middleware/logger.js";
|
||||
import { getTelemetryClient } from "../telemetry.js";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SSRF protection for plugin HTTP fetch
|
||||
|
|
@ -47,6 +48,7 @@ const DNS_LOOKUP_TIMEOUT_MS = 5_000;
|
|||
|
||||
/** Only these protocols are allowed for plugin HTTP requests. */
|
||||
const ALLOWED_PROTOCOLS = new Set(["http:", "https:"]);
|
||||
const TELEMETRY_EVENT_NAME_REGEX = /^[a-z0-9][a-z0-9_-]*$/;
|
||||
|
||||
/**
|
||||
* Check if an IP address is in a private/reserved range (RFC 1918, loopback,
|
||||
|
|
@ -636,6 +638,20 @@ export function buildHostServices(
|
|||
},
|
||||
},
|
||||
|
||||
telemetry: {
|
||||
async track(params) {
|
||||
const eventName = String(params.eventName ?? "").trim();
|
||||
if (!TELEMETRY_EVENT_NAME_REGEX.test(eventName)) {
|
||||
throw new Error(
|
||||
'Plugin telemetry event names must be lowercase slugs using letters, numbers, "_" or "-".',
|
||||
);
|
||||
}
|
||||
const telemetryClient = getTelemetryClient();
|
||||
if (!telemetryClient) return;
|
||||
telemetryClient.track(`plugin.${pluginKey}.${eventName}`, params.dimensions);
|
||||
},
|
||||
},
|
||||
|
||||
logger: {
|
||||
async log(params) {
|
||||
const { level, meta } = params;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue