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.28.0
Important Changes
- Beta release of official NestJS SDK
This release contains the beta version of @sentry/nestjs
! For details on how to use it, check out the
README. Any feedback/bug reports
are greatly appreciated, please reach out on GitHub.
- fix(browser): Remove faulty LCP, FCP and FP normalization logic (#13502)
This release fixes a bug in the @sentry/browser
package and all SDKs depending on this package (e.g. @sentry/react
or @sentry/nextjs
) that caused the SDK to send incorrect web vital values for the LCP, FCP and FP vitals. The SDK
previously incorrectly processed the original values as they were reported from the browser. When updating your SDK to
this version, you might experience an increase in LCP, FCP and FP values, which potentially leads to a decrease in your
performance score in the Web Vitals Insights module in Sentry. This is because the previously reported values were
smaller than the actually measured values. We apologize for the inconvenience!
Other Changes
- feat(nestjs): Add
SentryGlobalGraphQLFilter
(#13545) - feat(nestjs): Automatic instrumentation of nestjs interceptors after route execution (#13264)
- feat(nextjs): Add
bundleSizeOptimizations
to build options (#13323) - feat(nextjs): Stabilize
captureRequestError
(#13550) - feat(nuxt): Wrap config in nuxt context (#13457)
- feat(profiling): Expose profiler as top level primitive (#13512)
- feat(replay): Add layout shift to CLS replay data (#13386)
- feat(replay): Upgrade rrweb packages to 2.26.0 (#13483)
- fix(cdn): Do not mangle _metadata (#13426)
- fix(cdn): Fix SDK source for CDN bundles (#13475)
- fix(nestjs): Check arguments before instrumenting with
@Injectable
(#13544) - fix(nestjs): Ensure exception and host are correctly passed on when using @WithSentry (#13564)
- fix(node): Suppress tracing for transport request execution rather than transport creation (#13491)
- fix(replay): Consider more things as DOM mutations for dead clicks (#13518)
- fix(vue): Correctly obtain component name (#13484)
Work in this release was contributed by @leopoldkristjansson, @mhuggins and @filips123. Thank you for your
contributions!