Skip to content

feat: add structured logging with correlation IDs across API requests#428

Open
devAgatha wants to merge 1 commit into
AnnabelJoe:mainfrom
devAgatha:feat/273-structured-logging
Open

feat: add structured logging with correlation IDs across API requests#428
devAgatha wants to merge 1 commit into
AnnabelJoe:mainfrom
devAgatha:feat/273-structured-logging

Conversation

@devAgatha
Copy link
Copy Markdown

Summary

Adds pino-based structured JSON logging with per-request correlation IDs propagated across all log lines.

Changes

  • src/lib/logger.ts — pino logger with LOG_LEVEL env var, sensitive field redaction, pino-pretty in dev
  • src/lib/middleware/withLogging.tswithLogging() HOF that generates/reads x-correlation-id, logs request start/end with method, path, status, duration
  • src/app/api/readings/route.ts — wrapped with withLogging, structured log calls throughout
  • src/app/api/certificates/[id]/retire/route.ts — wrapped with withLogging

Acceptance Criteria

  • Structured JSON logs (pino)
  • Unique correlation ID generated per request and propagated to all log lines
  • Log level configurable via LOG_LEVEL env var
  • Sensitive fields (signature_hex, pubkey_hex, token, etc.) redacted from logs

Closes #273

- Add pino-based logger in lib/logger.ts with LOG_LEVEL env var support
- Redact sensitive fields (signature_hex, pubkey_hex, token, etc.)
- Add withLogging() middleware that generates/propagates x-correlation-id
- Apply to /api/readings and /api/certificates/[id]/retire routes
- Correlation ID echoed back in response header

Closes AnnabelJoe#273
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.

Add structured logging with correlation IDs across API requests

1 participant