Skip to content

feat: add correlation ID middleware for request tracing#170

Merged
Abdulazeem-code merged 4 commits into
Abdulazeem-code:mainfrom
noevidence1017:feat/correlation-ids
Jul 4, 2026
Merged

feat: add correlation ID middleware for request tracing#170
Abdulazeem-code merged 4 commits into
Abdulazeem-code:mainfrom
noevidence1017:feat/correlation-ids

Conversation

@noevidence1017

Copy link
Copy Markdown
Contributor

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

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Fix conflicts and backend build test error

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Check your backend build details to know what is causing the error and resolve it.
Please do this so that i can merge your pr

@noevidence1017

Copy link
Copy Markdown
Contributor Author

on it @Abdulazeem-code

@noevidence1017

Copy link
Copy Markdown
Contributor Author

@
Hi @Abdulazeem-code, thanks for the patience. I have resolved the issues you flagged.

The Backend Build & Test was failing on npm ci with an EJSONPARSE error, not on the tests themselves. When I merged main into this branch, the conflict resolution corrupted stellar-payment-platform/package.json: a comma was dropped after the uuid entry and sqlite3 ended up duplicated, which made the file invalid JSON. I also restored the correlationId import in server.js that was lost during the same merge.

What I fixed:

  • Repaired package.json (added the missing comma, removed the duplicate sqlite3 dependency) so it is valid JSON again.
  • Re-added const { correlationId } = require(./middleware/correlation); in server.js, since it was being used but no longer imported after the merge.
  • Regenerated package-lock.json so npm ci stays in sync.

Verified locally by running the exact CI steps against the latest main:

  • npm ci completes successfully.
  • npm test passes: 8 test suites, 132 tests, all green.

The branch is now up to date with main and conflict-free. The new workflow runs are showing action_required because this is a fork PR, so they need your approval to run. Whenever you get a chance to approve the workflows, the Backend Build & Test should pass. Thanks!
@

@Abdulazeem-code Abdulazeem-code merged commit a5f8a1d into Abdulazeem-code:main Jul 4, 2026
5 of 6 checks passed
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