Repository navigation
Description
Describe the feature you'd like to request
I’d like first-class OpenTelemetry (OTel) tracing support for
trpc/server
procedures and adapters.
Right now, instrumenting tRPC with OpenTelemetry requires manual wiring: setting up a tracer, wrapping adapters or resolvers, and remembering to create/finish spans for each procedure, including error tagging and context propagation. The building blocks exist in the OTEL ecosystem, but there’s no clear, “blessed” way to integrate them with tRPC’s router/procedure model and adapters.
A small, well-designed integration layer that makes “OTel-aware procedures and adapters” a first-class capability would make it much easier to run tRPC services with modern observability stacks (Grafana, Honeycomb, Datadog, etc.).
Describe the solution you'd like to see
I’d love to see built-in hooks in
trpc/server
that:
Expose a way to configure OpenTelemetry integration at the tRPC root level, e.g. via initTRPC.create({ ...telemetryOptions }), so that:
Each procedure call is wrapped in a span with a consistent, configurable naming convention (e.g. trpc.).
Common attributes are attached automatically (procedure type, path, success/error status, error code).
Errors are recorded as span events or error status with TRPCError information.
Integrate with existing adapters where possible (e.g. standalone, Node HTTP adapters) so that:
If an incoming HTTP request already has an active span, the tRPC procedure span becomes a child of that span.
Context propagation is handled in a predictable way without forcing users to manually thread OTEL context through ctx.
The exact API shape is open, but something along these lines would be very helpful (illustrative only, not a prescription):
ts
const t = initTRPC.create({
telemetry: {
// optional tracer or hooks
getTracer: () => otel.trace.getTracer('my-service'),
spanName: ({ path, type }) => trpc.${type}.${path},
onSpan: ({ span, ctx, input, error }) => {
// attach extra attributes or events if desired
},
},
});
Under the hood, this would hook into the existing procedure execution pipeline (in procedureBuilder / callProcedure) so that spans are created and ended around each call, and errors are mapped to OTEL span status/attributes. When telemetry is not configured, the behavior should remain exactly as it is today.
Ideally, the design would:
Keep OpenTelemetry optional (no hard dependency) but easy to plug in when available.
Work across adapters (standalone HTTP, Node HTTP, etc.), or clearly document which ones are supported in the first iteration.
Provide sensible defaults for span naming and attributes, while allowing users to customize via callbacks.
Describe alternate solutions
Current alternatives are:
Implement OTEL integration entirely in userland:
Manually wrap adapters to create spans around the handler.
Manually wrap procedure resolvers to create spans and handle error/span status mapping.
Handle context propagation and parent/child relationships on a per-project basis. This works, but it’s easy to get subtly wrong and tends to be duplicated across codebases.
Use community middleware packages:
There are third-party packages that attempt to integrate tRPC and OTEL, but they are not first-party and may not track internal changes to tRPC’s router/procedure internals.
There’s no canonical guidance in the tRPC docs on how to use them or how to structure telemetry for tRPC-specific concepts like routers/procedures.
A first-party tRPC integration layer would provide a canonical, documented approach designed specifically for
trpc/server
, reduce fragmentation, and make observability a natural part of building production services with tRPC.
Additional information
The current core already has a well-defined procedure execution path (initTRPC, procedureBuilder, callProcedure, adapters) that would be a natural insertion point for OTEL spans.
There are existing issues/discussions around tracing and observability in the broader ecosystem, and community packages that try to solve this, which suggests real demand for a “blessed” tRPC + OTEL story.
This feature would not introduce new concepts to tRPC users; it would formalize and package a pattern that many teams already implement manually, improving consistency, debuggability, and onboarding for production use cases.
👨👧👦 Contributing
- 🙋♂️ Yes, I'd be down to file a PR implementing this feature!
Activity
Nick-Lucas commentedon Nov 19, 2025
We try to leave this one up to the community because it's just a middleware and packages can provide middlewares for use. See this for example: https://github.com/baselime/trpc-opentelemetry-middleware
anatolzak commentedon Dec 11, 2025
@Nick-Lucas Thanks for the suggestion! This approach works well for standard queries and mutations, but it doesn’t cover procedures that return an async iterable for streaming. How would you recommend handling tracing for streaming queries?
Nick-Lucas commentedon Dec 11, 2025
Hey @anatolzak, so do let me know if there's anything else you'd expect tRPC to be able to do here, but this is my understanding:
There's probably a tidier way to write that (and it lacks error handling) but it worked for me with our minimal example project