Skip to content

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

sh
npm install @orpc/otel@latest
sh
yarn add @orpc/otel@latest
sh
pnpm add @orpc/otel@latest
sh
bun add @orpc/otel@latest
sh
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.

ts
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.

ts
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
)

Released under the MIT License.