Skip to content

fix: add request ID tracking for production debugging#165

Open
0x-SquidSol wants to merge 2 commits intodcccrypto:mainfrom
0x-SquidSol:fix/add-request-id-tracking
Open

fix: add request ID tracking for production debugging#165
0x-SquidSol wants to merge 2 commits intodcccrypto:mainfrom
0x-SquidSol:fix/add-request-id-tracking

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

Summary

  • Issue: Zero request correlation existed. If a user reported "I got a 500 at 3:15pm", ops could not find that specific request in logs or Sentry. No X-Request-Id header, no per-request identifier in logs, no correlation in Sentry events.
  • Fix: Adds Hono's built-in requestId() middleware for end-to-end request tracing.

How it works

  1. Middleware generates a UUID per request (or respects incoming X-Request-Id from load balancers)
  2. Response header X-Request-Id set on all responses — clients can quote it in bug reports
  3. Sentry tags every scope with request_id — filterable in Sentry dashboard
  4. Error responses include requestId field in JSON body:
    { "error": "Internal server error", "requestId": "550e8400-e29b-41d4-a716-446655440000" }
  5. Error logs include requestId for grep/search correlation

Changes

File Change
src/index.ts Import + register requestId() middleware; add requestId to error handler logs + response
src/middleware/sentry.ts Tag Sentry scope with request_id

Test plan

  • tsc --noEmit passes
  • vitest run passes (186/186 tests)
  • Manual: verify X-Request-Id header appears in responses
  • Manual: verify Sentry events are tagged with request_id

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Warning

Rate limit exceeded

@0x-SquidSol has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 46 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 46 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f6d0778f-1fe2-4dcd-9142-5cb23de82fee

📥 Commits

Reviewing files that changed from the base of the PR and between ed06944 and 191adca.

📒 Files selected for processing (3)
  • src/index.ts
  • src/middleware/sentry.ts
  • tests/routes/prices.test.ts
✨ 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.

Upstream changed /prices/:slab to ascending order + limit 1500
(for chart rendering), but the test still expected descending + 100.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@0x-SquidSol
Copy link
Copy Markdown
Contributor Author

⚠️ Merge conflict — needs rebase against current main

This PR has merge conflicts in src/index.ts and src/middleware/sentry.ts due to upstream changes:

The fix itself is still needed — no merged PR adds request ID / X-Request-Id correlation tracking. This is a new observability feature.

To resolve: Rebase against main and resolve conflicts. The requestId() middleware import and registration just need to be placed in the updated middleware chain, and the Sentry scope tag needs to go inside the updated withScope block.

No request correlation existed — if a user reported "I got a 500 at
3:15pm", ops could not find that specific request in logs or Sentry.

Adds Hono's built-in requestId() middleware which:
- Generates a UUID per request (or respects incoming X-Request-Id)
- Sets X-Request-Id response header on all responses
- Available via c.get("requestId") throughout the middleware chain

Integration points:
- Global error handler: logs requestId, includes it in error JSON response
- Sentry middleware: tags every scope with request_id for event correlation
- Error responses now include requestId so clients can quote it in reports

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant