mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50: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
|
|
@ -41,6 +41,7 @@ const manifest: PaperclipPluginManifestV1 = {
|
|||
"goals.update",
|
||||
"activity.log.write",
|
||||
"metrics.write",
|
||||
"telemetry.track",
|
||||
"plugin.state.read",
|
||||
"plugin.state.write",
|
||||
"events.subscribe",
|
||||
|
|
|
|||
|
|
@ -405,6 +405,16 @@ async function registerActionHandlers(ctx: PluginContext): Promise<void> {
|
|||
data: { companyId },
|
||||
});
|
||||
await ctx.metrics.write("demo.events.emitted", 1, { source: "manual" });
|
||||
await ctx.telemetry.track("demo_event", {
|
||||
source: "manual",
|
||||
has_company: Boolean(companyId),
|
||||
});
|
||||
pushRecord({
|
||||
level: "info",
|
||||
source: "telemetry",
|
||||
message: "Tracked plugin telemetry event demo_event",
|
||||
data: { companyId },
|
||||
});
|
||||
return { ok: true, message };
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -312,6 +312,7 @@ Declare in `manifest.capabilities`. Grouped by scope:
|
|||
| | `issue.comments.create` |
|
||||
| | `activity.log.write` |
|
||||
| | `metrics.write` |
|
||||
| | `telemetry.track` |
|
||||
| **Instance** | `instance.settings.register` |
|
||||
| | `plugin.state.read` |
|
||||
| | `plugin.state.write` |
|
||||
|
|
|
|||
|
|
@ -135,6 +135,11 @@ export interface HostServices {
|
|||
write(params: WorkerToHostMethods["metrics.write"][0]): Promise<void>;
|
||||
};
|
||||
|
||||
/** Provides `telemetry.track`. */
|
||||
telemetry: {
|
||||
track(params: WorkerToHostMethods["telemetry.track"][0]): Promise<void>;
|
||||
};
|
||||
|
||||
/** Provides `log`. */
|
||||
logger: {
|
||||
log(params: WorkerToHostMethods["log"][0]): Promise<void>;
|
||||
|
|
@ -284,6 +289,9 @@ const METHOD_CAPABILITY_MAP: Record<WorkerToHostMethodName, PluginCapability | n
|
|||
// Metrics
|
||||
"metrics.write": "metrics.write",
|
||||
|
||||
// Telemetry
|
||||
"telemetry.track": "telemetry.track",
|
||||
|
||||
// Logger — always allowed
|
||||
"log": null,
|
||||
|
||||
|
|
@ -447,6 +455,11 @@ export function createHostClientHandlers(
|
|||
return services.metrics.write(params);
|
||||
}),
|
||||
|
||||
// Telemetry
|
||||
"telemetry.track": gated("telemetry.track", async (params) => {
|
||||
return services.telemetry.track(params);
|
||||
}),
|
||||
|
||||
// Logger
|
||||
"log": gated("log", async (params) => {
|
||||
return services.logger.log(params);
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ export type {
|
|||
PluginStreamsClient,
|
||||
PluginToolsClient,
|
||||
PluginMetricsClient,
|
||||
PluginTelemetryClient,
|
||||
PluginLogger,
|
||||
} from "./types.js";
|
||||
|
||||
|
|
|
|||
|
|
@ -519,6 +519,12 @@ export interface WorkerToHostMethods {
|
|||
result: void,
|
||||
];
|
||||
|
||||
// Telemetry
|
||||
"telemetry.track": [
|
||||
params: { eventName: string; dimensions?: Record<string, string | number | boolean> },
|
||||
result: void,
|
||||
];
|
||||
|
||||
// Logger
|
||||
"log": [
|
||||
params: { level: "info" | "warn" | "error" | "debug"; message: string; meta?: Record<string, unknown> },
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ export interface TestHarness {
|
|||
logs: TestHarnessLogEntry[];
|
||||
activity: Array<{ message: string; entityType?: string; entityId?: string; metadata?: Record<string, unknown> }>;
|
||||
metrics: Array<{ name: string; value: number; tags?: Record<string, string> }>;
|
||||
telemetry: Array<{ eventName: string; dimensions?: Record<string, string | number | boolean> }>;
|
||||
}
|
||||
|
||||
type EventRegistration = {
|
||||
|
|
@ -132,6 +133,7 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
const logs: TestHarnessLogEntry[] = [];
|
||||
const activity: TestHarness["activity"] = [];
|
||||
const metrics: TestHarness["metrics"] = [];
|
||||
const telemetry: TestHarness["telemetry"] = [];
|
||||
|
||||
const state = new Map<string, unknown>();
|
||||
const entities = new Map<string, PluginEntityRecord>();
|
||||
|
|
@ -631,6 +633,12 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
metrics.push({ name, value, tags });
|
||||
},
|
||||
},
|
||||
telemetry: {
|
||||
async track(eventName, dimensions) {
|
||||
requireCapability(manifest, capabilitySet, "telemetry.track");
|
||||
telemetry.push({ eventName, dimensions });
|
||||
},
|
||||
},
|
||||
logger: {
|
||||
info(message, meta) {
|
||||
logs.push({ level: "info", message, meta });
|
||||
|
|
@ -729,6 +737,7 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
logs,
|
||||
activity,
|
||||
metrics,
|
||||
telemetry,
|
||||
};
|
||||
|
||||
return harness;
|
||||
|
|
|
|||
|
|
@ -761,6 +761,28 @@ export interface PluginMetricsClient {
|
|||
write(name: string, value: number, tags?: Record<string, string>): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* `ctx.telemetry` — emit plugin-scoped telemetry to the host's external
|
||||
* telemetry pipeline.
|
||||
*
|
||||
* Requires `telemetry.track` capability.
|
||||
*/
|
||||
export interface PluginTelemetryClient {
|
||||
/**
|
||||
* Track a plugin telemetry event.
|
||||
*
|
||||
* The host prefixes the final event name as `plugin.<pluginId>.<eventName>`
|
||||
* before forwarding it to the shared telemetry client.
|
||||
*
|
||||
* @param eventName - Bare plugin event slug (for example `"sync_completed"`)
|
||||
* @param dimensions - Optional structured dimensions
|
||||
*/
|
||||
track(
|
||||
eventName: string,
|
||||
dimensions?: Record<string, string | number | boolean>,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* `ctx.companies` — read company metadata.
|
||||
*
|
||||
|
|
@ -1156,6 +1178,9 @@ export interface PluginContext {
|
|||
/** Write plugin metrics. Requires `metrics.write`. */
|
||||
metrics: PluginMetricsClient;
|
||||
|
||||
/** Emit plugin-scoped external telemetry. Requires `telemetry.track`. */
|
||||
telemetry: PluginTelemetryClient;
|
||||
|
||||
/** Structured logger. Output is captured and surfaced in the plugin health dashboard. */
|
||||
logger: PluginLogger;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -793,6 +793,15 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
|||
},
|
||||
},
|
||||
|
||||
telemetry: {
|
||||
async track(
|
||||
eventName: string,
|
||||
dimensions?: Record<string, string | number | boolean>,
|
||||
): Promise<void> {
|
||||
await callHost("telemetry.track", { eventName, dimensions });
|
||||
},
|
||||
},
|
||||
|
||||
logger: {
|
||||
info(message: string, meta?: Record<string, unknown>): void {
|
||||
notifyHost("log", { level: "info", message, meta });
|
||||
|
|
|
|||
|
|
@ -448,6 +448,7 @@ export const PLUGIN_CAPABILITIES = [
|
|||
"agent.sessions.close",
|
||||
"activity.log.write",
|
||||
"metrics.write",
|
||||
"telemetry.track",
|
||||
// Plugin State
|
||||
"plugin.state.read",
|
||||
"plugin.state.write",
|
||||
|
|
|
|||
|
|
@ -33,4 +33,5 @@ export type TelemetryEventName =
|
|||
| "company.imported"
|
||||
| "agent.first_heartbeat"
|
||||
| "agent.task_completed"
|
||||
| "error.handler_crash";
|
||||
| "error.handler_crash"
|
||||
| `plugin.${string}`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue