/** * 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; /** 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 { const headers: Record = {}; 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 }; }