Skip to content

feat(api): add request id middleware with client header validation and tracing (#686) - #729

Open
ravendevhub wants to merge 1 commit into
Core-Foundry:mainfrom
ravendevhub:feat/request-id-middleware-686
Open

feat(api): add request id middleware with client header validation and tracing (#686)#729
ravendevhub wants to merge 1 commit into
Core-Foundry:mainfrom
ravendevhub:feat/request-id-middleware-686

Conversation

@ravendevhub

Copy link
Copy Markdown

Summary

Resolves #686 by introducing Request ID and Correlation ID tracing middleware for the NotifyChain API, validating client-supplied headers, attaching tracing identifiers to logs, and exposing X-Request-ID in HTTP response headers.

Changes

  1. Header Validation (listener/src/middleware/request-id.ts, listener/src/utils/request-id.ts):
    • Validates client-supplied X-Request-ID and X-Correlation-ID headers against safe alphanumeric/hyphen patterns (^[a-zA-Z0-9_-]{1,64}$).
    • Mints secure random UUIDv4 identifiers when client headers are missing or invalid.
  2. Response Header Exposure & Logging:
    • Automatically sets X-Request-ID and X-Correlation-ID response headers before flushing.
    • Binds resolved IDs to req.headers for downstream structured log context.
  3. Tests & Documentation:
    • Added comprehensive unit tests in request-id.test.ts verifying validation, sanitization, and response binding.
    • Documented contract and integration in docs/REQUEST_ID_MIDDLEWARE.md.

Acceptance Criteria

  • Each incoming request receives an identifier.
  • The identifier is included in relevant logs.
  • Responses expose the identifier where appropriate.
  • Client-supplied IDs are validated before reuse.

…d tracing (Core-Foundry#686)

- Validate client-supplied X-Request-ID and X-Correlation-ID headers (alphanumeric/hyphens <= 64 chars)
- Fallback to cryptographically random UUID generation on invalid/missing headers
- Expose X-Request-ID and X-Correlation-ID in HTTP response headers
- Attach validated IDs to request context for structured logging
- Add unit test coverage and specification in docs/REQUEST_ID_MIDDLEWARE.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Request ID Middleware

1 participant