Skip to content

feat: add correlation ID middleware for request tracing#170

Open
noevidence1017 wants to merge 2 commits into
Abdulazeem-code:mainfrom
noevidence1017:feat/correlation-ids
Open

feat: add correlation ID middleware for request tracing#170
noevidence1017 wants to merge 2 commits into
Abdulazeem-code:mainfrom
noevidence1017:feat/correlation-ids

Conversation

@noevidence1017

Copy link
Copy Markdown

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.

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

@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.

@drips-wave

drips-wave Bot commented Jun 24, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Abdulazeem-code

Copy link
Copy Markdown
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

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Fix backend build test error

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 Correlation ID Middleware for End-to-End Request Tracing

2 participants