Something went wrong. Try again.
claude code plugin that sends telemetry to otlp destinations (traces)
Something went wrong. Try again.
1.8 kB · 55 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556/** * Configuration — reads from standard OTel and plugin-specific env vars. */
export interface Config { /** OTLP endpoint (e.g. http://localhost:4318, https://api.honeycomb.io) */ endpoint: string; /** OTLP headers (e.g. x-honeycomb-team=KEY) */ headers: Record<string, string>; /** OTel service.name resource attribute */ serviceName: string; /** Path to the persistent state JSON file */ stateFilePath: string; /** Enable verbose debug logging */ debug: boolean; /** W3C traceparent to nest all traces under an external parent span */ parentTraceparent?: string;}
function parseHeaders(raw: string): Record<string, string> { const headers: Record<string, string> = {}; if (!raw) return headers; for (const pair of raw.split(",")) { const eq = pair.indexOf("="); if (eq > 0) { headers[pair.slice(0, eq).trim()] = pair.slice(eq + 1).trim(); } } return headers;}
export function loadConfig(): Config { const endpoint = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ?? process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://localhost:4318";
const headerStr = process.env.OTEL_EXPORTER_OTLP_TRACES_HEADERS ?? process.env.OTEL_EXPORTER_OTLP_HEADERS ?? ""; const headers = parseHeaders(headerStr);
const serviceName = process.env.OTEL_SERVICE_NAME ?? "claude-code";
const homeDir = process.env.HOME ?? process.env.USERPROFILE ?? ""; const stateFilePath = process.env.CC_OTEL_STATE_FILE ?? `${homeDir}/.claude/state/otel_tracing_state.json`;
const debug = (process.env.CC_OTEL_DEBUG ?? "").toLowerCase() === "true";
const parentTraceparent = process.env.CC_OTEL_TRACEPARENT || undefined;
return { endpoint, headers, serviceName, stateFilePath, debug, parentTraceparent };}