Skip to content

Propagate correlation/trace IDs end-to-end across HTTP, domain events, jobs, and webhooks #2156

Description

@RUKAYAT-CODER

Background

Requests, emitted domain events, background jobs, and outbound webhooks currently can't be correlated: a single logical operation (e.g. a payout) produces log lines and traces with no shared identifier, making incident debugging and latency attribution across async boundaries very hard. Tracing exists in common/tracing but the context is not carried across the event bus, the BullMQ job payloads, or webhook dispatch.

Implementation Plan

  • Generate/accept a correlation ID at the HTTP edge (interceptor/middleware) and store it in TracingService request context (AsyncLocalStorage)
  • Include the correlation ID in every emitted domain event payload and read it back in event handlers
  • Stamp the correlation ID onto enqueued job data and restore it at the start of each processor
  • Add the correlation ID to outbound webhook headers and to the structured logger's context so every log line carries it
  • Wire the interceptor globally in app.module.ts

Affected Files (7–8)

  • BackEnd/src/common/tracing/tracing.service.ts
  • BackEnd/src/common/tracing/correlation-id.interceptor.ts (new)
  • BackEnd/src/modules/trace/trace.service.ts
  • BackEnd/src/modules/jobs/processors/payout.processor.ts
  • BackEnd/src/modules/jobs/processors/webhook.processor.ts
  • BackEnd/src/modules/webhooks/webhooks.service.ts
  • BackEnd/src/common/logger/logger.module.ts
  • BackEnd/src/app.module.ts

Acceptance Criteria

  • Change is implemented end-to-end across the files above
  • Backward compatible — no regression in existing functionality
  • Unit and integration tests cover the new behavior (including failure paths)
  • No measurable performance regression on hot paths
  • Documentation / module CHANGELOG updated

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions