Skip to content

[Enhancement] Add structured correlation IDs to API requests for distributed tracing #657

Description

@RUKAYAT-CODER

Overview

API requests lack correlation IDs, making it impossible to trace a user action across multiple service calls in server logs. When a user reports a bug that requires analyzing 'what happened when I enrolled in course X', engineers must manually cross-reference timestamps across multiple log streams. A per-request UUID sent as X-Request-ID header enables instant log correlation.

Specifications

Features:

  • X-Request-ID header generated per API request (uuid v4)
  • Request ID included in all appLogger entries made during the request lifecycle
  • Request ID passed to Sentry context on error events
  • Server echoes X-Request-ID in response; client logs both sent and received IDs

Tasks:

  • In axios.config.ts request interceptor, generate UUID and set headers['X-Request-ID']
  • Store request ID in logContext via pushLogContext({ requestId })
  • In response interceptor, read echo'd header and log if different from sent (proxy stripping check)
  • Pop log context in response interceptor cleanup
  • Add unit test confirming X-Request-ID header present on all requests

Impacted Files:

  • src/services/api/axios.config.ts
  • src/config/logging.ts

Acceptance Criteria

  • Every API request carries unique X-Request-ID header
  • Request ID appears in all appLogger entries within the request lifecycle
  • Sentry error events include requestId in extra context
  • Unit test confirms UUID format and presence on all outbound requests

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions