Skip to content

feat(observability): add request ID correlation middleware [REN-71] - #109

Merged
Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-71-request-id-correlation
Mar 9, 2026
Merged

Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-71-request-id-correlation

Conversation

@cheddarfox

Copy link
Copy Markdown
Member

Summary

  • Add RequestIdMiddleware generating a UUID per request and binding it to structlog contextvars so all log statements automatically include request_id
  • Return X-Request-ID in response headers for client-side correlation
  • Accept client-provided X-Request-ID header to support distributed tracing across edge nodes and gateway (OWASP A09 remediation)
  • Store request ID on request.state for direct access in route handlers

Test plan

  • Responses include X-Request-ID header with a valid UUID
  • Logs include request_id field automatically (via structlog contextvars)
  • Client-provided X-Request-ID is echoed back unchanged
  • Missing X-Request-ID generates a new UUID (not empty)
  • ruff check passes on all changed files

🤖 Generated with Claude Code

Add RequestIdMiddleware that generates a UUID per request, binds it to
structlog contextvars for automatic inclusion in all log output, and
returns it via the X-Request-ID response header. Accepts client-provided
X-Request-ID to support distributed tracing across edge nodes and
gateway services (OWASP A09 remediation).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cheddarfox

Copy link
Copy Markdown
Member Author

ARCHitect Review — REN-71 ✅ APPROVED

structlog contextvars binding, client X-Request-ID propagation, outermost middleware position. Enables distributed tracing.

🤖 Generated with Claude Code

@cheddarfox
Scott Graham (cheddarfox) merged commit 09cc6ae into dev Mar 9, 2026
15 of 17 checks passed
@cheddarfox
Scott Graham (cheddarfox) deleted the REN-71-request-id-correlation branch March 9, 2026 22:52
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