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';
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);
provider.register({
propagator: new SentryPropagator(),
contextManager: new SentryContextManager(),
});
setOpenTelemetryContextAsyncContextStrategy();
}
A full setup example can be found in
node-experimental.
Links
8.29.0
Important Changes
- Beta releases of official Solid and SolidStart Sentry SDKs
This release marks the beta releases of the @sentry/solid
and @sentry/solidstart
Sentry SDKs. For details on how to
use them, check out the
Sentry Solid SDK README and the
Sentry SolidStart SDK README
respectively. Please reach out on GitHub if you have
any feedback or concerns.
- feat(node): Option to only wrap instrumented modules (#13139)
Adds the SDK option to only wrap ES modules with import-in-the-middle
that specifically need to be instrumented.
import * as Sentry from '@sentry/node';
Sentry.init({
dsn: '__PUBLIC_DSN__',
registerEsmLoaderHooks: { onlyIncludeInstrumentedModules: true },
});
- feat(node): Update OpenTelemetry packages to instrumentation v0.53.0 (#13587)
All internal OpenTelemetry instrumentation was updated to their latest version. This adds support for Mongoose v7 and v8
and fixes various bugs related to ESM mode.
Other Changes
- feat(nextjs): Emit warning when using turbopack (#13566)
- feat(nextjs): Future-proof Next.js config options overriding (#13586)
- feat(node): Add
generic-pool
integration (#13465) - feat(nuxt): Upload sourcemaps generated by Nitro (#13382)
- feat(solidstart): Add
browserTracingIntegration
by default (#13561) - feat(solidstart): Add
sentrySolidStartVite
plugin to simplify source maps upload (#13493) - feat(vue): Only start UI spans if parent is available (#13568)
- fix(cloudflare): Guard
context.waitUntil
call in request handler (#13549) - fix(gatsby): Fix assets path for sourcemaps upload (#13592)
- fix(nextjs): Use posix paths for sourcemap uploads (#13603)
- fix(node-fetch): Use stringified origin url (#13581)
- fix(node): Replace dashes in
generic-pool
span origins with underscores (#13579) - fix(replay): Fix types in WebVitalData (#13573)
- fix(replay): Improve replay web vital types (#13602)
- fix(utils): Keep logger on carrier (#13570)
Work in this release was contributed by @Zen-cronic. Thank you for your contribution!