Sentry Integration
Sentry is a powerful tool for error tracking and performance monitoring. This guide explains how to integrate oRPC with Sentry to capture errors and performance metrics in your applications.
WARNING
This guide assumes familiarity with Sentry. Review the official documentation if needed.
INFO
This integration is based on the OpenTelemetry Integration, so you can refer to that guide for more details on setting up OpenTelemetry with oRPC.
Installation
npm install @orpc/otel@latest
yarn add @orpc/otel@latest
pnpm add @orpc/otel@latest
bun add @orpc/otel@latest
deno install npm:@orpc/otel@latest
Setup
To set up OpenTelemetry with oRPC, use the ORPCInstrumentation
class. This class automatically instruments your oRPC client and server for distributed tracing.
import * as Sentry from '@sentry/node'
import { ORPCInstrumentation } from '@orpc/otel'
Sentry.init({
dsn: '...',
sendDefaultPii: true,
tracesSampleRate: 1.0, // enable tracing
openTelemetryInstrumentations: [
new ORPCInstrumentation(),
]
})
Capturing Errors
Since Sentry does not yet support collecting OpenTelemetry span events, you should capture errors that occur in business logic manually. You can use interceptors
, middleware
, or other error handling mechanisms.
import * as Sentry from '@sentry/node'
import { os } from '@orpc/server'
export const sentryMiddleware = os.middleware(async ({ next }) => {
try {
return await next()
}
catch (error) {
Sentry.captureException(error)
throw error
}
})
export const base = os.use(sentryMiddleware)