feat: add correlation ID middleware for request tracing#170
Open
noevidence1017 wants to merge 2 commits into
Open
feat: add correlation ID middleware for request tracing#170noevidence1017 wants to merge 2 commits into
noevidence1017 wants to merge 2 commits into
Conversation
|
@noevidence1017 is attempting to deploy a commit to the Abdulazeem's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@noevidence1017 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
Could you click the Update branch button on your end, or run git pull origin main locally and push? That will make the tests pass so I can merge this!" Fix conflict |
Owner
|
Fix backend build test error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #31
What
Adds a correlation ID middleware that gives every incoming request a unique tracking ID, making it possible to trace all log lines belonging to a single API call across middleware layers and async tasks.
Changes
New middleware/correlation.js: checks for an inbound X-Correlation-ID header and reuses it when present; otherwise generates a uuidv4. The value is exposed on req.correlationId, set as the outbound X-Correlation-ID response header, and used to prefix a per-request log line emitted on response finish.
Mounted the middleware globally at the top of the Express stack in server.js, ahead of CORS and body parsing, so the ID is available to every downstream handler and error path.
Updated the global error handler so 500 logs are prefixed with the correlation ID, and the ID is returned in the error response body alongside the existing reference ID.
Added the uuid dependency (pinned to ^9.0.1 to remain CommonJS-compatible with the existing Jest setup).
Testing
Existing Jest suite passes (28 passed).
Verified that requests without the header receive a generated ID and that an inbound X-Correlation-ID is preserved and echoed back.