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
10.22.0
Important Changes
-
feat(node): Instrument cloud functions for firebase v2 (#17952)
We added instrumentation for Cloud Functions for Firebase v2, enabling automatic performance tracking and error monitoring. This will be added automatically if you have enabled tracing.
-
feat(core): Instrument LangChain AI (#17955)
Instrumentation was added for LangChain AI operations. You can configure what is recorded like this:
Sentry.init({
integrations: [
Sentry.langChainIntegration({
recordInputs: true, // Record prompts/messages
recordOutputs: true, // Record responses
}),
],
});
Other Changes
- feat(cloudflare,vercel-edge): Add support for LangChain instrumentation (#17986)
- feat: Align sentry origin with documentation (#17998)
- feat(core): Truncate request messages in AI integrations (#17921)
- feat(nextjs): Support node runtime on proxy files (#17995)
- feat(node): Pass requestHook and responseHook option to OTel (#17996)
- fix(core): Fix wrong async types when instrumenting anthropic's stream api (#18007)
- fix(nextjs): Remove usage of chalk to avoid runtime errors (#18010)
- fix(node): Pino capture serialized
err (#17999)
- fix(node): Pino child loggers (#17934)
- fix(react): Don't trim index route
/ when getting pathname (#17985)
- fix(react): Patch
spanEnd for potentially cancelled lazy-route transactions (#17962)
<details>
<summary> <strong>Internal Changes</strong> </summary>
- chore: Add required size_check for GH Actions (#18009)
- chore: Upgrade madge to v8 (#17957)
- test(hono): Fix hono e2e tests (#18000)
- test(react-router): Fix
getMetaTagTransformer tests for Vitest compatibility (#18013)
- test(react): Add parameterized route tests for
createHashRouter (#17789)
</details>