Skip to content

[BE-136] Add request correlation IDs to Winston logging (BE-32 was closed but not implemented) #966

Description

@mftee

Overview

The backend has a proper Winston setup (nest-winston, buildWinstonOptions, configurable LOG_LEVEL) — good groundwork. What is missing is correlation: nothing ties the log lines belonging to a single request together, so tracing a document through upload → risk assessment → queue → Stellar anchoring means guessing.

Note on history: issue [BE-32] "Add correlation IDs to all requests for end-to-end log tracing" is closed — and appears twice in the issue history, both closed. However the implementation is not present in the codebase:

  • backend/src/common/logger.config.ts sets timestamp, error, and JSON formats only — no correlation field.
  • No middleware or interceptor generates or attaches a request ID.
  • Searching for correlation, requestId, or x-request-id across backend/src returns only an unrelated domain field in external-validation.service.ts (a validation request's own primary key, not an HTTP correlation ID).

So this is not a duplicate of BE-32 — it is the same work, re-opened because it was marked done without landing. Please verify against the current code before closing this one.

Tasks

  • Generate a request ID per incoming request, honouring an inbound X-Request-Id, and echo it on the response.
  • Attach the request ID to every log line automatically via a Winston child logger or async local storage.
  • Propagate the request ID into BullMQ job payloads so async work traces back to its trigger.
  • Include the request ID in error responses so a user-reported error maps to server logs.
  • Add redaction for authorization, cookie, password, and token fields.
  • Ensure production logs are structured JSON.

Acceptance Criteria

  • Every log line carries a request ID.
  • Filtering by one request ID shows the full lifecycle including queued work.
  • No secret appears in log output (covered by a test).

Notes for Contributors

Comment below to be assigned.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendbugSomething isn't workingnestjs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions