Skip to content

P1: Structured JSON logging with request correlation ids (#172)#190

Open
dkijania wants to merge 1 commit into
mainfrom
feat/structured-logging
Open

P1: Structured JSON logging with request correlation ids (#172)#190
dkijania wants to merge 1 commit into
mainfrom
feat/structured-logging

Conversation

@dkijania

Copy link
Copy Markdown
Contributor

What & why

Part of the production-readiness epic (#163). Closes #172.

Logging used console.info/error and an inspect(..., {colors:true}) error dump — TTY-oriented, not aggregation-friendly — with no request ids, and was entangled with the Jaeger toggle.

Changes

  • logger.ts — a pino structured logger: JSON lines, ISO timestamps, level from LOG_LEVEL (invalid values fall back to info instead of throwing at startup), independent of tracing.
  • useRequestLogging plugin — assigns each request a correlation id (honouring an inbound X-Request-Id) and emits one structured access line per request with method, path, status, durationMs. Probe endpoints (/healthcheck, /readiness) are skipped to avoid orchestrator noise.
  • GraphQL execution errors now log as structured JSON tagged with the same requestId.
  • console.* in the entry point replaced with the logger.

New dependency: pino.

Testing

  • npm run build — clean
  • npm run test:unit — all pass; new tests cover level parsing/fallback and prove (through Yoga) the access-line shape, X-Request-Id correlation, and probe-path suppression
  • npm run lint / npx prettier --debug-check . — clean

🤖 Generated with Claude Code

Logging used `console.info/error` and an `inspect(..., {colors:true})` error
dump — TTY-oriented, not aggregation-friendly — with no request ids, and was
entangled with the Jaeger toggle.

- Add a pino-based structured logger (`logger.ts`): JSON lines, ISO timestamps,
  level from `LOG_LEVEL` (invalid values fall back to `info` instead of
  throwing), independent of tracing.
- Add a `useRequestLogging` plugin that assigns each request a correlation id
  (honouring an inbound `X-Request-Id`) and emits one structured access line per
  request with method, path, status, and duration. Probe endpoints
  (`/healthcheck`, `/readiness`) are skipped to avoid orchestrator noise.
- GraphQL execution errors now log as structured JSON tagged with the same
  `requestId`; `console.*` in the entry point replaced with the logger.

Unit tests cover level parsing/fallback and prove (through Yoga) the access
line shape, X-Request-Id correlation, and probe-path suppression.

Closes #172.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSuak9smCHbp4N17xjjLF6
@dkijania dkijania added production-readiness Work toward making the API production-ready / publicly available P1 Strongly recommended before GA labels Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Strongly recommended before GA production-readiness Work toward making the API production-ready / publicly available

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P1: Structured JSON logging with request/correlation IDs

1 participant