feat(context): add structured request context storage using AsyncLocalStorage - #153
Conversation
…lStorage Implement a structured, typed request context store backed by AsyncLocalStorage (RequestContext) that captures routing metadata, resolved principal and request-scoped values for the lifetime of each HTTP request. - Add RequestContext store with typed identity/principal getters, scoped data storage and timing recording, propagated through async continuations - Add RequestContextInterceptor that seeds the context on every request, resolving identity from JWT auth or implicit org/agent headers - Register the interceptor globally ahead of the existing agent trace interceptor - Add unit tests for the store and interceptor Closes ASTROIDX556#80
|
@Aj-Kayvee 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! 🚀 |
|
MergeKeeper review Scope: in scope for linked issue Successfully implements structured request context storage using AsyncLocalStorage and a global interceptor with comprehensive test coverage. Reviewed commit: |
|
MergeKeeper merge status Status: blocked Reason: Next steps:
|
Closes #80
Summary
Implements a structured, typed request context store built on Node's
AsyncLocalStorage, giving every request a single, request-scoped snapshot of routing metadata, the resolved principal, and arbitrary request-scoped values that propagates through all async continuations.Changes
src/common/context/request-context.ts- newRequestContextstore (singleAsyncLocalStorage):RequestContextDatagrouped intoidentity(requestId, correlationId, traceId, method, path, url, ip, userAgent, startedAt),principal(userId, organizationId, agentId, role, authMethod),timings, anddata.getRequestId,getCorrelationId,getTraceId,getMethod,getPath,getStartedAt,getUserId,getOrganizationId,getAgentId,getPrincipal).setPrincipal,setData/getData, andmarkTiming/getTimingfor request-scoped state.src/common/interceptors/request-context.interceptor.ts- new global interceptor that seeds the context on every HTTP request, resolving identity from JWT auth or implicit organization/agent headers.src/app.module.ts- registersRequestContextInterceptorglobally ahead of the existing agent-trace interceptor.request-context.spec.tsandrequest-context.interceptor.spec.ts(vitest).Verification
npm run typecheck- passesnpm run lint- passesnpm run test- 251 tests pass (30 files), including 12 new tests