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.12.0
Important Changes
-
feat(feedback): Implement highlighting and hiding controls for screenshots (#15951)
The Sentry SDK now supports highlighting and hiding controls for screenshots in user feedback reports. This functionality is enabled by default.
-
feat(node): Add ignoreIncomingRequestBody
callback to httpIntegration
(#15959)
The httpIntegration
now supports an optional ignoreIncomingRequestBody
callback that can be used to skip capturing the body of incoming requests.
Sentry.init({
integrations: [
Sentry.httpIntegration({
ignoreIncomingRequestBody: (url, request) => {
return request.method === 'GET' && url.includes('/api/large-payload');
},
}),
],
});
The ignoreIncomingRequestBody
callback receives the URL of the request and should return true
if the body should be ignored.
-
Logging Improvements
Sentry is adding support for structured logging. In this release we've made a variety of improvements to logging functionality in the Sentry SDKs.
- feat(node): Add server.address to nodejs logs (#16006)
- feat(core): Add sdk name and version to logs (#16005)
- feat(core): Add sentry origin attribute to console logs integration (#15998)
- fix(core): Do not abbreviate message parameter attribute (#15987)
- fix(core): Prefix release and environment correctly (#15999)
- fix(node): Make log flushing logic more robust (#15991)
Other Changes
- build(aws-serverless): Include debug logs in lambda layer SDK bundle (#15974)
- feat(astro): Add tracking of errors during HTML streaming (#15995)
- feat(browser): Add
onRequestSpanStart
hook to browser tracing integration (#15979)
- feat(deps): Bump @sentry/cli from 2.42.3 to 2.43.0 (#16001)
- feat(nextjs): Add
captureRouterTransitionStart
hook for capturing navigations (#15981)
- feat(nextjs): Mark clientside prefetch request spans with
http.request.prefetch: true
attribute (#15980)
- feat(nextjs): Un experimentify
clientInstrumentationHook
(#15992)
- feat(nextjs): Warn when client was initialized more than once (#15971)
- feat(node): Add support for
SENTRY_DEBUG
env variable (#15972)
- fix(tss-react): Change
authToken
type to string
(#15985)
Work in this release was contributed by @Page- and @Fryuni. Thank you for your contributions!