Skip to content

feat(observability): inject traceId/spanId into pino logs for Loki-Tempo correlation (ANGA-1020)#161

Open
anhermon wants to merge 1 commit into
masterfrom
feature/anga-1020-otel-pino-v2
Open

feat(observability): inject traceId/spanId into pino logs for Loki-Tempo correlation (ANGA-1020)#161
anhermon wants to merge 1 commit into
masterfrom
feature/anga-1020-otel-pino-v2

Conversation

@anhermon

Copy link
Copy Markdown
Owner

Summary

  • Adds @opentelemetry/api ^1.9.0 as a direct dependency of server (was only an implicit transitive dep via sdk-node; making it direct gives a stable import and ensures pnpm links it correctly)
  • Adds a mixin to the pino logger in server/src/middleware/logger.ts that reads the active OTel span context and injects traceId + spanId into every log line
  • When no span is active (or OTel is not initialized), getTraceContext() returns {} — zero-cost no-op with no performance impact

Background

ANGA-1020 — parent ANGA-384

Work plan items 1–3 (OTel packages, tracing.ts, initTracing() call) were already merged in c40a3f013. This PR delivers item 4: traceId/spanId correlation in pino logs — the last outstanding piece so Loki log entries can be correlated with Tempo traces by traceId.

Changes (2 files)

  • server/package.json — add @opentelemetry/api ^1.9.0 as direct dependency
  • server/src/middleware/logger.ts — add getTraceContext() helper and pino mixin

Note: no lockfile changes included — CI owns lockfile updates per policy.

Test plan

  • TypeScript build passes (tsc --noEmit)
  • With observability stack running (docker compose -f docker-compose.yml -f docker-compose.observability.yml up), Loki log lines include traceId + spanId fields
  • Without PAPERCLIP_OTEL_ENDPOINT, no trace fields appear and server starts normally

🤖 Generated with Claude Code

…relation (ANGA-1020)

Injects the active OpenTelemetry traceId and spanId into every pino log
line via a mixin so that Loki log entries can be correlated with Tempo
traces by traceId. Adds @opentelemetry/api as a direct server dependency
(was previously only an implicit transitive dep of sdk-node); the api
package is already resolved at 1.9.1 in the lockfile.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@github-actions

Copy link
Copy Markdown

Benchmark Score: 86/100 (passing)

Dimension Score Weight
tests 100.0 15%
coverage 69.7 20%
typecheck 100.0 10%
build 100.0 10%
security 70.0 15%
codeHealth 81.8 15%
lint 96.4 10%
docs 93.5 5%

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.

2 participants