Something went wrong. Try again.
claude code plugin that sends telemetry to otlp destinations (traces)
Something went wrong. Try again.
3.0 kB · 90 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import { describe, it, expect, beforeEach, afterEach } from "vitest";import { loadConfig } from "./config.js";
describe("loadConfig", () => { const originalEnv = { ...process.env };
beforeEach(() => { // Clear relevant env vars delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT; delete process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT; delete process.env.OTEL_EXPORTER_OTLP_HEADERS; delete process.env.OTEL_EXPORTER_OTLP_TRACES_HEADERS; delete process.env.OTEL_SERVICE_NAME; delete process.env.CC_OTEL_STATE_FILE; delete process.env.CC_OTEL_DEBUG; delete process.env.CC_OTEL_TRACEPARENT; });
afterEach(() => { Object.assign(process.env, originalEnv); });
it("defaults endpoint to localhost:4318", () => { expect(loadConfig().endpoint).toBe("http://localhost:4318"); });
it("reads OTEL_EXPORTER_OTLP_ENDPOINT", () => { process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://api.honeycomb.io"; expect(loadConfig().endpoint).toBe("https://api.honeycomb.io"); });
it("prefers OTEL_EXPORTER_OTLP_TRACES_ENDPOINT over generic", () => { process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://generic.endpoint"; process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = "https://traces.endpoint"; expect(loadConfig().endpoint).toBe("https://traces.endpoint"); });
it("parses OTEL_EXPORTER_OTLP_HEADERS", () => { process.env.OTEL_EXPORTER_OTLP_HEADERS = "x-honeycomb-team=abc123,x-other=val"; const headers = loadConfig().headers; expect(headers["x-honeycomb-team"]).toBe("abc123"); expect(headers["x-other"]).toBe("val"); });
it("returns empty headers when not set", () => { expect(loadConfig().headers).toEqual({}); });
it("defaults serviceName to 'claude-code'", () => { expect(loadConfig().serviceName).toBe("claude-code"); });
it("reads custom service name", () => { process.env.OTEL_SERVICE_NAME = "my-service"; expect(loadConfig().serviceName).toBe("my-service"); });
it("reads custom state file path", () => { process.env.CC_OTEL_STATE_FILE = "/custom/state.json"; expect(loadConfig().stateFilePath).toBe("/custom/state.json"); });
it("defaults debug to false", () => { expect(loadConfig().debug).toBe(false); });
it("enables debug with 'true'", () => { process.env.CC_OTEL_DEBUG = "true"; expect(loadConfig().debug).toBe(true); });
it("enables debug case-insensitively", () => { process.env.CC_OTEL_DEBUG = "TRUE"; expect(loadConfig().debug).toBe(true); });
it("does not enable debug with other values", () => { process.env.CC_OTEL_DEBUG = "1"; expect(loadConfig().debug).toBe(false); });
it("reads CC_OTEL_TRACEPARENT", () => { process.env.CC_OTEL_TRACEPARENT = "00-abc123-def456-01"; expect(loadConfig().parentTraceparent).toBe("00-abc123-def456-01"); });
it("returns undefined for parentTraceparent when not set", () => { expect(loadConfig().parentTraceparent).toBeUndefined(); });});