forked from farhoodlabs/paperclip
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:
@@ -68,6 +68,7 @@ const OPERATION_CAPABILITIES: Record<string, readonly PluginCapability[]> = {
|
||||
"issue.comments.create": ["issue.comments.create"],
|
||||
"activity.log": ["activity.log.write"],
|
||||
"metrics.write": ["metrics.write"],
|
||||
"telemetry.track": ["telemetry.track"],
|
||||
|
||||
// Plugin state operations
|
||||
"plugin.state.get": ["plugin.state.read"],
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user