Skip to content

fix: return x-request-id in response headers for client-side tracing#1454

Open
Xenon010101 wants to merge 1 commit into
Sachinchaurasiya360:mainfrom
Xenon010101:fix/issue-1441-x-request-id
Open

fix: return x-request-id in response headers for client-side tracing#1454
Xenon010101 wants to merge 1 commit into
Sachinchaurasiya360:mainfrom
Xenon010101:fix/issue-1441-x-request-id

Conversation

@Xenon010101
Copy link
Copy Markdown
Contributor

@Xenon010101 Xenon010101 commented Jun 5, 2026

What

x-request-id was generated for tracing but never returned to the client in response headers.

Root cause

The middleware in server/src/index.ts generated a UUID on req.headers but never called res.setHeader() to send it back.

Changes

  • server/src/index.ts: Changed _res to res and added res.setHeader("x-request-id", ...) after generating the ID

Verification

  • Change is minimal (2 insertions)
  • No side effects on existing behavior

CI failures

N/A

Before

Request ID generated but never returned to client.

After

All API responses include x-request-id header for client-side tracing.

Closes #1441

Summary by CodeRabbit

  • Bug Fixes
    • Request ID tracing middleware now properly sets request identifiers in API response headers, enabling clients to receive and track request IDs with every API response.

The middleware generated a unique x-request-id for tracing but never
sent it back to the client. Added res.setHeader so clients can correlate
their requests with server-side logs.

Closes Sachinchaurasiya360#1441

Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
@github-actions github-actions Bot added bug Something isn't working gssoc level:beginner Good for first-time contributors quality:exceptional Exceptional implementation quality labels Jun 5, 2026
@github-actions github-actions Bot added gssoc:approved Approved for GSSoC scoring scope:backend Changes to server-side / API code labels Jun 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Hi @Xenon010101, thanks for contributing to InternHack! 🎉

I have automatically:

  • 👤 Assigned this PR to you.
  • 🏷️ Applied the gssoc:approved label.

Our workflows will now analyze your changes to classify:

  • 📈 PR Difficulty: level:*
  • 🧩 PR Type: type:*
  • 🌟 PR Quality: quality:*

Tip

Ensure your PR description references the issue it resolves (e.g. Closes #123). This allows the bot to inherit any additional labels from that issue!

Happy coding! 🚀

@github-actions github-actions Bot added type:bug Bug fixes type:devops CI/CD, deployment, or infra changes labels Jun 5, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 79a71b1e-f3d8-4448-8e4a-931c0beee121

📥 Commits

Reviewing files that changed from the base of the PR and between 0c176ae and 28df304.

📒 Files selected for processing (1)
  • server/src/index.ts

📝 Walkthrough

Walkthrough

The request-id tracing middleware in server/src/index.ts is updated to propagate the unique request identifier back to clients. The middleware continues to generate a new UUID when the incoming request lacks an x-request-id header, and now additionally sets that ID on the response headers for client visibility.

Changes

Request-ID response header propagation

Layer / File(s) Summary
Request-ID response header
server/src/index.ts
Middleware now sets the x-request-id response header after ensuring the request ID is present (generated via crypto.randomUUID() when missing). The actual res parameter is used instead of the unused _res parameter.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through request logs so bright,
With tracing IDs now returned just right,
From server to client, the ID will flow,
Each response header wears its UUID glow! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: returning x-request-id in response headers for client-side tracing, which is the primary objective of this PR.
Description check ✅ Passed The PR description covers the what, root cause, and changes made, but lacks explicit information about testing methods and doesn't follow all template sections.
Linked Issues check ✅ Passed The PR directly addresses issue #1441 by implementing the required fix: changing _res to res and adding res.setHeader() to return x-request-id in response headers.
Out of Scope Changes check ✅ Passed All changes in this PR are directly scoped to the linked issue #1441; the 2-line modification only addresses the missing x-request-id response header.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gssoc:approved Approved for GSSoC scoring gssoc level:beginner Good for first-time contributors quality:exceptional Exceptional implementation quality scope:backend Changes to server-side / API code type:bug Bug fixes type:devops CI/CD, deployment, or infra changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Bug: x-request-id is generated for tracing but never returned to the client in Response headers

1 participant