/create_plan @thoughts/shared/research/2026-04-07-orpc-observability-middleware.md
Private research annotation
Sign in to add a private research label or note.
- User
/create_plan @thoughts/shared/research/2026-04-07-orpc-observability-middleware.md
- User
create_plan /create_plan @thoughts/shared/research/2026-04-07-orpc-observability-middleware.md
Assistant· claude-opus-4-6
I've read the research document. Let me now gather context from the codebase by reading the key implementation files and spawning research agents in parallel.
Assistant· claude-opus-4-6
Now let me check the API contract and see how
ORPCErrorstatus works.Assistant· claude-opus-4-6
Let me find how oRPC packages are installed and check the
ORPCErrorstatus property.Assistant· claude-opus-4-6
Let me check the ORPCError class for its
.statusproperty and see iftoORPCErroris available.Assistant· claude-opus-4-6
Good. Now I have all the information I need. Let me read the COMMON_ORPC_ERROR_DEFS to confirm the status codes and then also look at the
toORPCErrorfunction.Assistant· claude-opus-4-6
Let me check the oRPC middleware
pathtype format.Assistant· claude-opus-4-6
Good —
pathisreadonly string[]in oRPC. Let me check the middleware type more precisely.Assistant· claude-opus-4-6
Let me check how the tRPC observability middleware is wired up in the app.
Assistant· claude-opus-4-6
Let me check the existing oRPC dependency setup.
Assistant· claude-opus-4-6
I now have a comprehensive understanding of the codebase. Here's my proposed plan structure:
Based on the research and my analysis of all the relevant files, I understand we need to create an observability middleware for the oRPC
/v1/*API layer that matches the capabilities already present in the tRPC and Inngest layers.Key findings from my analysis:
vendor/observability/src/trpc.tsis the reference pattern — Sentry isolation scope, span, ALS context, error classification, journal- oRPC middleware (
os.middleware()) has the same structural pattern as tRPC — wrapsnext()in an async function - Critical difference: oRPC errors propagate as thrown exceptions (vs tRPC's / result pattern), requiring a try/catch wrapper inside
- User
makes snese proceed
Assistant· claude-opus-4-6
I've created the implementation plan at:
thoughts/shared/plans/2026-04-07-orpc-observability-middleware.md3 phases:
-
Foundation — Add
enrichContext()helper tocontext.ts+ parameterizeemitJournalprefix (backward-compatible, no behavioral change to existing tRPC/Inngest) -
Core middleware — Create
vendor/observability/src/orpc.tswithcreateORPCObservabilityMiddleware(). Key design: catches errors insidewithRequestContext(since oRPC throws instead of returningresult.ok), usesORPCError.statusdirectly for error classification, joinspath[]with.for span names -
Integration — Wire into
apps/app: observability middleware before auth, auth middleware enriches ALS with auth fields viaenrichContext(), remove 3 manuallog.infocalls from handlers, addcaptureExceptionto route handler's outer catch
Please review it and let me know:
- Are the phases properly scoped?
-