Skip to content

Request correlation - #1673

Open
Devadakene wants to merge 6 commits into
Stellar-Mail:mainfrom
Devadakene:request-correlation
Open

Request correlation#1673
Devadakene wants to merge 6 commits into
Stellar-Mail:mainfrom
Devadakene:request-correlation

Conversation

@Devadakene

Copy link
Copy Markdown

Closes #1473

Problem

Currently, request execution and repository actions are not unified with request correlation metadata. When errors or validations fail at the repository or adapter boundaries, matching them to the originating HTTP request is difficult.

Solution

This PR introduces request-scoped tracking using AsyncLocalStorage to store the active context (requestId, method, route). Downstream components are modified to query and link with this context seamlessly:

  • Request Context Store: Introduced RequestContext via AsyncLocalStorage in src/server/api/context.ts.
  • API Handler Wrapping: Modified route execution inside createRouteHandler (src/server/api/handler.ts) to run within the active context storage. Structured logger invocations are integrated to record metrics and logs with the request ID.
  • Repository Validation: Updated getApiContext to ensure the repositories are wrapped in ValidatedApiRepository so record boundaries are checked uniformly.
  • Error Correlation: Intercepted repository actions using a correlation decorator inside ValidatedApiRepository to bind the active requestId to any repository errors. DataIntegrityError retrieves its correlation ID from the active context.
  • Unit Testing: Added tests/unit/api/request-correlation.test.ts to assert context propagation, error correlation, and structured logging metrics.

Acceptance Criteria Verified

  • Repository errors carry the originating requestId.
  • Request IDs appear in structured logs.
  • Domain models are not polluted with transport-only fields.
  • Tests confirm propagation across route handlers.

@kryputh

kryputh commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

@Devadakene tell your agent to run bun command with prettier to format the code

Then check ✅ it again with bun after with bun prettier check ✅...

That the case for all your issues. If you have CODEX try using it or just connect your GitHub with GPT and use chatGPT work with the GitHub mcp

It should also solve it

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.

Propagate request IDs through repository and domain service calls

2 participants