Skip to content

feat(server): add OpenTelemetry instrumentation - #36

Open
espetro wants to merge 1 commit into
feat/pipeline-migrationfrom
feat/otel-instrumentation
Open

feat(server): add OpenTelemetry instrumentation#36
espetro wants to merge 1 commit into
feat/pipeline-migrationfrom
feat/otel-instrumentation

Conversation

@espetro

@espetro espetro commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds initOTel() (@app/logger/otel) wiring OTLP HTTP trace + metric exporters, called at server startup with SIGTERM/SIGINT-triggered graceful shutdown.
  • Adds GET /api/metrics (Prometheus text format) exposing pipeline token usage counters from @calca/pipeline's tokenAggregator.
  • Adds otel-local.yaml for running a local OTel Collector during development.
  • Pins @opentelemetry/{sdk-metrics,resources,sdk-trace-node} to 1.29.0 via root package.json overrides to avoid version skew with sdk-node's transitive deps.

Stacked on #34 (pipeline-migration) — this branch bases off feat/pipeline-migration since @calca/pipeline (the tokenAggregator import in /api/metrics) only exists after that PR.

Test plan

  • packages/logger: tsc --noEmit clean, vitest run — 8 passed
  • apps/server: tsc --noEmit clean, vitest run — 15 passed, 1 pre-existing failure unrelated to this change (workflow.test.ts fails on a zod version mismatch inside packages/shared/src/schemas/layout.ts, which this PR doesn't touch)
  • Manual verification: ran a local OTel Collector via Docker (otel/opentelemetry-collector + otel-local.yaml), started the server with OTEL_ENABLED=true — SDK initializes without error, /api/metrics returns valid Prometheus-format output, collector's OTLP HTTP receiver on :4318 accepts trace payloads (200 + partialSuccess).
  • Note: @opentelemetry/instrumentation-http patches Node's node:http module, which Bun's native Bun.serve() does not go through — inbound request spans are not auto-instrumented for this reason. This is a Bun-runtime limitation rather than a bug in this PR; outbound fetch() calls remain covered by FetchInstrumentation.

Adds OTLP HTTP trace/metric export via @app/logger/otel, a Prometheus-format
/api/metrics endpoint for pipeline token usage, and graceful shutdown on
SIGTERM/SIGINT. OTel deps pinned to 1.29.0 to avoid version skew across
@opentelemetry/{sdk-metrics,resources,sdk-trace-node}.

Closes #31
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying calca with  Cloudflare Pages  Cloudflare Pages

Latest commit: f0c7a91
Status: ✅  Deploy successful!
Preview URL: https://2a5de2f3.calca-5u3.pages.dev
Branch Preview URL: https://feat-otel-instrumentation.calca-5u3.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant