Skip to content

Add request correlation ID propagation middleware and logging interceptor #120

Description

@Cjay-Cyber-2

Description — what to implement and the why/impact.

Tracing asynchronous operations, database queries, and background job dispatches across the NestJS modular monolith requires a consistent request correlation ID. This task implements a middleware that extracts or generates a correlation ID for every incoming HTTP request and propagates it through AsyncLocalStorage and outbound log contexts.

Context & Requirements — background, constraints, design references, edge cases; grounded in the actual repo (real files, stack, conventions).

The repository already incorporates AsyncLocalStorage context storage. This issue ensures that incoming HTTP requests automatically populate the context with a correlation ID (from X-Request-ID or generated via UUID v4), include it in the standard response envelope requestId, and attach it to NestJS Logger outputs for every request lifecycle phase.

Acceptance Criteria — a checklist ("- [ ] ...") of specific, testable conditions that define "done".

  • Implement NestJS middleware to capture or generate X-Request-ID headers.
  • Bind the correlation ID into the AsyncLocalStorage execution context.
  • Ensure the uniform response envelope includes the request ID in its metadata.
  • Add unit tests verifying correlation ID persistence and propagation across nested service calls.

Implementation Guidance — likely files/modules to touch (use real paths from the repo context) and a suggested approach, without over-prescribing.

Examine src/common and existing interceptors or middleware. Implement the correlation middleware and register it globally in src/app.module.ts or via consumer configuration.

Testing & Validation — how the contributor should prove it works (tests to add/run, manual checks, screenshots for UI).

Run npm test and npm run typecheck to verify correct typing and behavior of the context storage middleware.

Submission Guidelines — must open a PR that includes "Closes #"; assignment is required before starting; follow the repo's existing style and conventions.


Wave complexity: Medium

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions