PR: #363: feat(otel): repoint correlation_id to trace_id browser+server + regen [Story-1454] by @ankitmaheshwari-com
View PR →
Story 1454 · EPIC-1400 Observability trace graph migration (Phase-2) · R7b

Repoint correlation_id → trace_id across the app's browser + server consumers, and regenerate src/gen

The founder decision (2026-06-19) retires the homegrown correlation_id and standardizes request identity on the W3C / OTel trace_id. Story-1453 (R7a, functions, merged) already flipped the canonical contract: ErrorResponse now carries a top-level trace_id instead of correlation_id. This Story is the lockstep app consumer: it stops minting the correlation id at the edge, repoints the six named consumers to trace_id, and regenerates src/gen against the new OpenAPI. Per the founder accept-the-fold decision it also deletes the now-dead cid files (the app file-deletion originally scoped to Story-1457), keeping correlation.ts/-context.ts only where still-live out-of-scope code (incl. the Bug-1471 outbound-headers.ts) depends on them.

1 — Re-sync the contract mirror + regenerate src/gen

Per openapi/AGENTS.md + HR-22, the contract source of truth is pramaan-functions. The vendored mirror was synced from functions origin/main (Story-1453, PR #378) and codegen run with the repo's own command — no hand-edits to src/gen.

cp ../pramaan-functions/openapi/app-api.json openapi/app-api.json
pnpm codegen   # rm -rf src/gen/{types,zod,schemas,client,hooks,index.ts} && kubb generate

The contract delta is small but ripples wide: the ErrorResponse schema's @description literally embeds the phrase “a nested error object plus a top-level trace_id”, and that description is copied into every endpoint's error-response schema. So the regen touches 152 generated files (813 ins / 813 del) — all deterministic description + field renames, codegen-drift clean.

ShapeBeforeAfter
ErrorResponse{ correlation_id, error }{ error, trace_id } (required string)
HealthResponsecorrelation_idcorrelation_id (unchanged — out of scope)

2 — Drop the cid mint at the edge (proxy.ts)

The proxy no longer mints or stamps x-pramaan-correlation-id on the request or the response. Request identity now flows on trace_id alone, and the proxy observability log keys on trace_id/span_id (the correlation_id / had_incoming_id fields are simply omitted now). The x-pramaan-route header and the entire pramaan-docs ADR-104 traceparent path are untouched.

// src/proxy.ts — stampRequestContext (cid mint removed; traceparent kept)
request.headers.set(REQUEST_ROUTE_HEADER, request.nextUrl.pathname);
const traceparent = resolveTraceparent(request.headers.get(TRACEPARENT_HEADER));
// ...mint/respect/strip traceparent exactly as before...
return { traceId, spanId };   // no correlationId, no hadIncomingId

Critically, the Bug-1471 fix in src/lib/outbound-headers.ts is byte-for-byte untouched — the connected X-Ray graph depends on outbound backend calls carrying the active @vercel/otel span's traceparent, and that single-sourcing is preserved.

3 — Repoint the six named consumers to trace_id

Each consumer now reads/carries trace_id instead of correlation_id. The browser source of truth is the RSC layout's <meta name="x-pramaan-trace-id"> (surfaced in Story-1447); the server source is the proxy-stamped traceparent header.

ConsumerRepoint
kubb-client.tsStops reading the cid response header (no trace_id is echoed per-fetch); keeps merging upstream service-identity headers into window.pramaan.
pramaan-diagnostics.tswindow.pramaan now exposes trace_id (and window.__pramaan.traceId), seeded from the meta tag; updatePramaanCorrelationId → updatePramaanTraceId.
bug-report (bug-report.ts, report-bug-client.ts, use-report-bug-submit.ts, route, report-bug-diagnostics.ts)Payload carries trace_id; the GitHub issue body shows Trace ID; the S3 screenshot key + object metadata key on trace_id.
client-error (client-error-reporter.ts + route)Drops the correlation_id leg; the report + log line carry trace_id only.
invite-flow.tsLog line keys on trace_id (resolved from the active span, falling back to the request traceparent).
business-action-log.tsSame: the ADR-064 business-action log line emits trace_id.

So a bug report or a client render error now carries the live X-Ray trace_id end to end — support resolves the failing request directly in the X-Ray graph.

4 — Regen-forced server builders (the “server” half)

Because ErrorResponse is built with satisfies ErrorResponse in the BFF, the regen forces every error-body builder to switch correlation_id → trace_id: the shared _helpers.ts (apiError/validationError) and the 16 route handlers that hand-roll their own inline builders. They all route through one shared resolver:

// src/app/api/internal/_helpers.ts
export function resolveRequestTraceId(request: NextRequest): string {
  // On this BFF surface the @vercel/otel route span CONTINUES the proxy-stamped
  // inbound traceparent (Bug-1471), so its exported X-Ray trace id EQUALS the
  // traceparent's trace id. Reading the header gives the same value without
  // importing the OTel API into every /api/internal route's module graph.
  return parseTraceparent(request.headers.get(TRACEPARENT_HEADER) ?? "")?.traceId ?? "";
}

5 — Delete the dead cid files (accept-the-fold)

Per the founder decision to align with the admin repoint (Story-1455), this PR deletes the now-dead correlation-id files rather than leaving them inert — absorbing the app file-deletion originally scoped to Story-1457 (APP-RIP). The only remaining RIP is the functions cross-lane contract cleanup (Story-1456).

Verification green

Out of scope (dependent / sibling EPIC-1400 tickets)

This PR absorbed Story-1457's app file-deletion (accept-the-fold), so the correlation-provider/-banner/-reference files are gone. What remains by design: correlation.ts / correlation-context.ts stay because still-live out-of-scope code depends on them — REQUEST_ROUTE_HEADER in proxy.ts, the /api/health route (keeps correlation_id per the unchanged HealthResponse), gateway.ts, and the Bug-1471 outbound-headers.ts correlation context (deliberately untouched). Story-1455 (R7c) is the parallel admin repoint; Story-1456 (R7d) is the functions cid rip-out. The live staging connected-graph test across X-Ray + CloudWatch + Logfire is the EPIC-1400 program-level acceptance gate.

Files changed

212 file(s), +1182 / -1260 lines

Path Role + -
openapi/app-api.jsonConfig+7-7
src/app/[locale]/(workspace)/clients/[clientId]/error.tsxApp route+2-2
src/app/[locale]/(workspace)/clients/error.tsxApp route+2-2
src/app/[locale]/(workspace)/error.tsxApp route+2-2
src/app/[locale]/error.tsxApp route+2-2
src/app/[locale]/layout.tsxApp route+6-17
src/app/[locale]/not-found.tsxApp route+2-2
src/app/api/bug-report/route.tsApp route+2-2
src/app/api/internal/_helpers.tsApp route+21-2
src/app/api/internal/client-error/route.tsApp route+0-2
src/app/api/internal/clients/[clientId]/route.tsApp route+3-3
src/app/api/internal/clients/route.tsApp route+3-3
src/app/api/internal/filing-types/[filingTypeId]/route.tsApp route+2-2
src/app/api/internal/firm-roles/[firmRoleId]/route.tsApp route+2-3
src/app/api/internal/forums/[forumId]/route.tsApp route+2-2
src/app/api/internal/forums/route.tsApp route+2-2
src/app/api/internal/inference/policy/route.tsApp route+2-2
src/app/api/internal/matter-templates/[matterTemplateId]/route.tsApp route+3-3
src/app/api/internal/matter-templates/route.tsApp route+2-2
src/app/api/internal/matter-types/[matterTypeId]/route.tsApp route+3-3
src/app/api/internal/matter-types/route.tsApp route+2-2
src/app/api/internal/matters/route.tsApp route+2-2
src/app/api/internal/participant-labels/[participantLabelId]/route.tsApp route+3-3
src/app/api/internal/participant-labels/route.tsApp route+2-2
src/app/api/internal/proceeding-types/[proceedingTypeId]/route.tsApp route+3-3
src/app/api/internal/proceeding-types/route.tsApp route+2-2
src/components/app-not-found.stories.tsxComponent+3-7
src/components/app-not-found.tsxComponent+2-2
src/components/app-transient-error.tsxComponent+2-2
src/components/correlation-banner.stories.tsxComponent+0-25
src/components/correlation-banner.tsxComponent+0-16
src/components/observability/error-toast.tsxComponent+4-4
src/components/report-bug/report-bug-client.tsComponent+11-3
src/components/report-bug/use-report-bug-submit.tsComponent+2-2
src/components/{correlation-reference.stories.tsx => trace-reference.stories.tsx}Component+8-17
src/components/{correlation-reference.tsx => trace-reference.tsx}Component+36-11
src/gen/schemas/errorResponse.jsonGenerated contract+7-7
src/gen/types/ErrorResponse.tsGenerated contract+6-6
src/gen/zod/appArchiveClientSchema.tsGenerated contract+6-6
src/gen/zod/appArchiveFilingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appArchiveMatterTemplateSchema.tsGenerated contract+6-6
src/gen/zod/appArchiveMatterTypeSchema.tsGenerated contract+6-6
src/gen/zod/appArchiveParticipantLabelSchema.tsGenerated contract+6-6
src/gen/zod/appArchiveProceedingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appAssignMatterProceedingParticipantRoleSchema.tsGenerated contract+5-5
src/gen/zod/appCreateClaimBlockRefSchema.tsGenerated contract+6-6
src/gen/zod/appCreateClaimRbrLinkSchema.tsGenerated contract+6-6
src/gen/zod/appCreateClaimValidationCheckSchema.tsGenerated contract+5-5
src/gen/zod/appCreateClientSchema.tsGenerated contract+6-6
src/gen/zod/appCreateDocumentBlockSchema.tsGenerated contract+5-5
src/gen/zod/appCreateEntityAffiliationSchema.tsGenerated contract+5-5
src/gen/zod/appCreateEntitySchema.tsGenerated contract+5-5
src/gen/zod/appCreateFilingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appCreateFirmRoleSchema.tsGenerated contract+6-6
src/gen/zod/appCreateForumSchema.tsGenerated contract+6-6
src/gen/zod/appCreateMatterAdversaryReadSchema.tsGenerated contract+6-6
src/gen/zod/appCreateMatterAnnotationSchema.tsGenerated contract+6-6
src/gen/zod/appCreateMatterClaimSchema.tsGenerated contract+5-5
src/gen/zod/appCreateMatterParticipantSchema.tsGenerated contract+5-5
src/gen/zod/appCreateMatterProceedingFilingSchema.tsGenerated contract+5-5
src/gen/zod/appCreateMatterProceedingSchema.tsGenerated contract+5-5
src/gen/zod/appCreateMatterProceedingStageSchema.tsGenerated contract+6-6
src/gen/zod/appCreateMatterProceedingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appCreateMatterRbrSchema.tsGenerated contract+6-6
src/gen/zod/appCreateMatterSchema.tsGenerated contract+5-5
src/gen/zod/appCreateMatterTemplateSchema.tsGenerated contract+6-6
src/gen/zod/appCreateMatterTypeSchema.tsGenerated contract+6-6
src/gen/zod/appCreateParticipantLabelSchema.tsGenerated contract+6-6
src/gen/zod/appCreateProceedingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appCreateRelatedMatterCarryForwardRecordSchema.tsGenerated contract+5-5
src/gen/zod/appCreateRelatedMatterSchema.tsGenerated contract+6-6
src/gen/zod/appDeactivateMemberSchema.tsGenerated contract+5-5
src/gen/zod/appDeleteClaimBlockRefSchema.tsGenerated contract+5-5
src/gen/zod/appDeleteClaimRbrLinkSchema.tsGenerated contract+5-5
src/gen/zod/appDeleteClientSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteEntityAffiliationSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteFilingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteFirmRoleSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteForumSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteMatterClaimSchema.tsGenerated contract+5-5
src/gen/zod/appDeleteMatterParticipantSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteMatterTemplateSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteMatterTypeSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteParticipantLabelSchema.tsGenerated contract+6-6
src/gen/zod/appDeleteProceedingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appDocumentAuditTimelineSchema.tsGenerated contract+5-5
src/gen/zod/appFilingAuditTimelineSchema.tsGenerated contract+5-5
src/gen/zod/appFinalizeDocumentUploadSchema.tsGenerated contract+6-6
src/gen/zod/appGetAppMeSchema.tsGenerated contract+5-5
src/gen/zod/appGetClaimBlockRefSchema.tsGenerated contract+5-5
src/gen/zod/appGetClaimRbrLinkSchema.tsGenerated contract+5-5
src/gen/zod/appGetClientSchema.tsGenerated contract+5-5
src/gen/zod/appGetConfigScreenBootstrapSchema.tsGenerated contract+4-4
src/gen/zod/appGetCurrentFirmProfileSchema.tsGenerated contract+5-5
src/gen/zod/appGetDocumentBlockSchema.tsGenerated contract+5-5
src/gen/zod/appGetDocumentDownloadUrlSchema.tsGenerated contract+6-6
src/gen/zod/appGetEntitySchema.tsGenerated contract+5-5
src/gen/zod/appGetFilingTypeSchema.tsGenerated contract+5-5
src/gen/zod/appGetInferencePolicySchema.tsGenerated contract+4-4
src/gen/zod/appGetMatterAdversaryReadSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterAnnotationSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterClaimSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterProceedingSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterRbrSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterTemplateSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterTemplateSnapshotSchema.tsGenerated contract+5-5
src/gen/zod/appGetMatterValidationCheckSchema.tsGenerated contract+5-5
src/gen/zod/appGetProfileSchema.tsGenerated contract+5-5
src/gen/zod/appGetSeatsAndBillingSchema.tsGenerated contract+6-6
src/gen/zod/appListAgentAuditSchema.tsGenerated contract+5-5
src/gen/zod/appListAppFirmMembershipsSchema.tsGenerated contract+6-6
src/gen/zod/appListAuditSchema.tsGenerated contract+5-5
src/gen/zod/appListClaimBlockRefsSchema.tsGenerated contract+5-5
src/gen/zod/appListClaimRbrLinksSchema.tsGenerated contract+5-5
src/gen/zod/appListClaimValidationChecksSchema.tsGenerated contract+5-5
src/gen/zod/appListClientsSchema.tsGenerated contract+4-4
src/gen/zod/appListDocumentBlocksSchema.tsGenerated contract+5-5
src/gen/zod/appListEntitiesSchema.tsGenerated contract+4-4
src/gen/zod/appListEntityAffiliationsSchema.tsGenerated contract+5-5
src/gen/zod/appListFilingTypesSchema.tsGenerated contract+4-4
src/gen/zod/appListFirmRolesSchema.tsGenerated contract+4-4
src/gen/zod/appListForumsSchema.tsGenerated contract+4-4
src/gen/zod/appListHumanAuditSchema.tsGenerated contract+5-5
src/gen/zod/appListInferenceProvidersSchema.tsGenerated contract+4-4
src/gen/zod/appListMatterAdversaryReadsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterAnnotationsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterClaimsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterDocumentsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterParticipantsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterProceedingFilingsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterProceedingParticipantRolesSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterProceedingStagesSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterProceedingsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterRbrsSchema.tsGenerated contract+5-5
src/gen/zod/appListMatterTemplatesSchema.tsGenerated contract+4-4
src/gen/zod/appListMatterTypesSchema.tsGenerated contract+4-4
src/gen/zod/appListMatterValidationChecksSchema.tsGenerated contract+5-5
src/gen/zod/appListMattersSchema.tsGenerated contract+4-4
src/gen/zod/appListMembersSchema.tsGenerated contract+5-5
src/gen/zod/appListParticipantLabelsSchema.tsGenerated contract+4-4
src/gen/zod/appListProceedingAdversaryReadsSchema.tsGenerated contract+5-5
src/gen/zod/appListProceedingTypesSchema.tsGenerated contract+4-4
src/gen/zod/appListRelatedMatterCarryForwardRecordsSchema.tsGenerated contract+5-5
src/gen/zod/appListRelatedMattersSchema.tsGenerated contract+5-5
src/gen/zod/appListSupportGrantsSchema.tsGenerated contract+5-5
src/gen/zod/appListTargetAnnotationsSchema.tsGenerated contract+5-5
src/gen/zod/appMatterAuditTimelineSchema.tsGenerated contract+5-5
src/gen/zod/appPatchMatterAdversaryReadResponseSchema.tsGenerated contract+6-6
src/gen/zod/appPatchMatterAdversaryReadStateSchema.tsGenerated contract+6-6
src/gen/zod/appPresignDocumentUploadSchema.tsGenerated contract+5-5
src/gen/zod/appProceedingAuditTimelineSchema.tsGenerated contract+5-5
src/gen/zod/appReactivateMemberSchema.tsGenerated contract+5-5
src/gen/zod/appResolveMatterValidationCheckSchema.tsGenerated contract+6-6
src/gen/zod/appRevokeSupportGrantSchema.tsGenerated contract+5-5
src/gen/zod/appSelectAppActiveFirmSchema.tsGenerated contract+6-6
src/gen/zod/appSetInferencePolicySchema.tsGenerated contract+6-6
src/gen/zod/appSubjectAuditTimelineSchema.tsGenerated contract+5-5
src/gen/zod/appUnarchiveClientSchema.tsGenerated contract+6-6
src/gen/zod/appUnarchiveFilingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appUnarchiveMatterTemplateSchema.tsGenerated contract+6-6
src/gen/zod/appUnarchiveMatterTypeSchema.tsGenerated contract+6-6
src/gen/zod/appUnarchiveParticipantLabelSchema.tsGenerated contract+6-6
src/gen/zod/appUnarchiveProceedingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateClaimBlockRefSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateClaimRbrLinkSchema.tsGenerated contract+5-5
src/gen/zod/appUpdateClientSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateDocumentBlockSchema.tsGenerated contract+5-5
src/gen/zod/appUpdateEntityAffiliationSchema.tsGenerated contract+5-5
src/gen/zod/appUpdateEntitySchema.tsGenerated contract+5-5
src/gen/zod/appUpdateExtraUsageSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateFilingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateFirmRoleSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateForumSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateMatterAnnotationSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateMatterClaimSchema.tsGenerated contract+5-5
src/gen/zod/appUpdateMatterParticipantSchema.tsGenerated contract+5-5
src/gen/zod/appUpdateMatterProceedingSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateMatterProceedingStageSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateMatterProceedingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateMatterSchema.tsGenerated contract+5-5
src/gen/zod/appUpdateMatterTemplateSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateMatterTypeSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateMemberFirmRoleSchema.tsGenerated contract+5-5
src/gen/zod/appUpdateParticipantLabelSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateProceedingTypeSchema.tsGenerated contract+6-6
src/gen/zod/appUpdateProfileSchema.tsGenerated contract+5-5
src/gen/zod/errorResponseSchema.tsGenerated contract+7-7
src/lib/bug-report.test.tsLibrary+5-5
src/lib/bug-report.tsLibrary+4-4
src/lib/business-action-log.tsLibrary+14-7
src/lib/client-error-reporter.tsLibrary+4-16
src/lib/correlation-provider.tsxLibrary+0-35
src/lib/invite-flow.tsLibrary+17-11
src/lib/kubb-client.tsLibrary+6-9
src/lib/logger-browser.tsLibrary+17-10
src/lib/pramaan-diagnostics.tsLibrary+27-13
src/lib/proxy-observability.tsLibrary+16-5
src/lib/report-bug-diagnostics.tsLibrary+2-2
src/proxy.tsSource+15-57
tests/unit/app-not-found.test.tsxTest+16-10
tests/unit/bug-report-route.test.tsTest+2-2
tests/unit/correlation-banner.test.tsxTest+0-41
tests/unit/error-toast.test.tsxTest+30-16
tests/unit/lib/business-action-log.test.tsTest+4-3
tests/unit/lib/kubb-client.test.tsTest+3-4
tests/unit/lib/pramaan-diagnostics.test.tsTest+7-7
tests/unit/lib/report-bug-diagnostics.test.tsTest+4-4
tests/unit/proxy-trace.test.tsTest+5-4
tests/unit/proxy.test.tsTest+6-6
tests/unit/report-bug-submit.test.tsxTest+2-2
tests/unit/{correlation-reference.test.tsx => trace-reference.test.tsx}Test+11-6