Skip to content

feat: add Request Interceptor and request ID generation utilities (#2176) - #2179

Open
nagi1 wants to merge 1 commit into
devlikeapro:devfrom
nagi1:feature/2176-add-unique-request-identifier-to-logs
Open

feat: add Request Interceptor and request ID generation utilities (#2176)#2179
nagi1 wants to merge 1 commit into
devlikeapro:devfrom
nagi1:feature/2176-add-unique-request-identifier-to-logs

Conversation

@nagi1

@nagi1 nagi1 commented Jul 23, 2026

Copy link
Copy Markdown

This pull request introduces infrastructure for request ID tracing to improve request correlation and observability. It adds a configurable request ID header, generates or propagates request IDs, and ensures the request ID is included in responses. The changes also include comprehensive tests for these features.

Request ID tracing and propagation:

  • Added a new module src/nestjs/requestId.ts providing:

    • generateRequestId for extracting or generating a request ID (UUID v4) from incoming requests, using a configurable header (WAHA_REQUEST_ID_HEADER, defaulting to x-request-id).
    • RequestIdInterceptor, a NestJS interceptor that writes the request ID to the response header, matching the incoming header name.
    • getRequestIdHeader utility for retrieving the configured header name.
  • Integrated request ID tracing into the core app:

    • Registered RequestIdInterceptor as a global interceptor in PROVIDERS_BASE to ensure all responses include the request ID header.
    • Configured pino-http logging to use generateRequestId, ensuring consistent request ID usage in logs and tracing.
    • Imported the new tracing utilities into the core module.

Testing and reliability:

  • Added a comprehensive test suite in src/nestjs/requestId.test.ts covering:
    • Header configuration and environment variable overrides.
    • Request ID extraction, generation, and propagation logic.
    • Behavior of the RequestIdInterceptor under various scenarios, including custom headers and edge cases.

patron:PLUS

@nagi1

nagi1 commented Jul 23, 2026

Copy link
Copy Markdown
Author

Related issue: #2176

patron:PLUS

@nagi1

nagi1 commented Jul 29, 2026

Copy link
Copy Markdown
Author

@devlikepro Kind Reminder to review and merge this!

patron:PLUS

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant