Official Sentry SDK for OpenTelemetry

This package allows you to send your OpenTelemetry trace data to Sentry via OpenTelemetry SpanProcessors.
If you are using @sentry/node
, OpenTelemetry support is included out of the box. This package is only necessary if you
are setting up OpenTelemetry support for Sentry yourself.
Installation
npm install @sentry/opentelemetry
yarn add @sentry/opentelemetry
Note that @sentry/opentelemetry
depends on the following peer dependencies:
@opentelemetry/api
version 1.0.0
or greater
@opentelemetry/core
version 1.0.0
or greater
@opentelemetry/semantic-conventions
version 1.0.0
or greater
@opentelemetry/sdk-trace-base
version 1.0.0
or greater, or a package that implements that, like
@opentelemetry/sdk-node
.
Usage
This package exposes a few building blocks you can add to your OpenTelemetry setup in order to capture OpenTelemetry
traces to Sentry.
This is how you can use this in your app:
- Initialize Sentry, e.g.
@sentry/node
!
- Call
setupEventContextTrace(client)
- Add
SentrySampler
as sampler
- Add
SentrySpanProcessor
as span processor
- Add a context manager wrapped via
wrapContextManagerClass
- Add
SentryPropagator
as propagator
- Setup OTEL-powered async context strategy for Sentry via
setOpenTelemetryContextAsyncContextStrategy()
For example, you could set this up as follows:
import * as Sentry from '@sentry/node';
import {
SentryPropagator,
SentrySampler,
SentrySpanProcessor,
setupEventContextTrace,
wrapContextManagerClass,
setOpenTelemetryContextAsyncContextStrategy,
} from '@sentry/opentelemetry';
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
import { context, propagation, trace } from '@opentelemetry/api';
function setupSentry() {
Sentry.init({
dsn: 'xxx',
});
const client = Sentry.getClient();
setupEventContextTrace(client);
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
});
provider.addSpanProcessor(new SentrySpanProcessor());
const SentryContextManager = wrapContextManagerClass(AsyncLocalStorageContextManager);
trace.setGlobalTracerProvider(provider);
propagation.setGlobalPropagator(new SentryPropagator());
context.setGlobalContextManager(new SentryContextManager());
setOpenTelemetryContextAsyncContextStrategy();
}
A full setup example can be found in
node-experimental.
Links
9.14.0
Important Changes
- feat: Add Supabase Integration (#15719)
This PR adds Supabase integration to @sentry/core
, allowing automatic instrumentation of Supabase client operations (database queries and authentication) for performance monitoring and error tracking.
- feat(nestjs): Gracefully handle RPC scenarios in
SentryGlobalFilter
(#16066)
This PR adds better RPC exception handling to @sentry/nestjs
, preventing application crashes while still capturing errors and warning users when a dedicated filter is needed. The implementation gracefully handles the 'rpc' context type in SentryGlobalFilter
to improve reliability in hybrid applications.
- feat(react-router): Trace propagation (#16070)
This PR adds trace propagation to @sentry/react-router
by providing utilities to inject trace meta tags into HTML headers and offering a pre-built Sentry-instrumented request handler, improving distributed tracing capabilities across page loads.
Other Changes
- feat(deps): Bump @prisma/instrumentation from 6.5.0 to 6.6.0 (#16102)
- feat(nextjs): Improve server component data (#15996)
- feat(nuxt): Log when adding HTML trace meta tags (#16044)
- fix(node): Make body capturing more robust (#16105)
- ref(node): Log when incoming request bodies are being captured (#16104)