Official Sentry SDK for OpenTelemetry
This package allows you to send your OpenTelemetry trace data to Sentry via OpenTelemetry SpanProcessors.
This SDK is considered experimental and in an alpha state. It may experience breaking changes. Please reach out on
GitHub if you have any feedback/concerns.
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.10.0
Important Changes
- feat(remix): Migrate to
opentelemetry-instrumentation-remix
. (#12110)
You can now simplify your remix instrumentation by opting-in like this:
const Sentry = require('@sentry/remix');
Sentry.init({
dsn: YOUR_DSN
// opt-in to new auto instrumentation
autoInstrumentRemix: true,
});
With this setup, you do not need to add e.g. wrapExpressCreateRequestHandler
anymore. Additionally, the quality of the
captured data improves. The old way to use @sentry/remix
continues to work, but it is encouraged to use the new setup.
Other Changes
- feat(browser): Export
thirdPartyErrorFilterIntegration
from @sentry/browser
(#12512) - feat(feedback): Allow passing
tags
field to any feedback config param (#12197) - feat(feedback): Improve screenshot quality for retina displays (#12487)
- feat(feedback): Screenshots don't resize after cropping (#12481)
- feat(node) add max lineno and colno limits (#12514)
- feat(profiling) add global profile context while profiler is running (#12394)
- feat(react): Add React version to events (#12390)
- feat(replay): Add url to replay hydration error breadcrumb type (#12521)
- fix(core): Ensure standalone spans respect sampled flag (#12533)
- fix(core): Use maxValueLength in extra error data integration (#12174)
- fix(feedback): Fix scrolling after feedback submission (#12499)
- fix(feedback): Send feedback rejects invalid responses (#12518)
- fix(nextjs): Update @rollup/plugin-commonjs (#12527)
- fix(node): Ensure status is correct for http server span errors (#12477)
- fix(node): Unify
getDynamicSamplingContextFromSpan
(#12522) - fix(profiling): continuous profile chunks should be in seconds (#12532)
- fix(remix): Add nativeFetch support for accessing request headers (#12479)
- fix(remix): Export no-op as
captureRemixServerException
from client SDK (#12497) - ref(node) refactor contextlines to use readline (#12221)
Work in this release was contributed by @AndreyKovanov and @kiliman. Thank you for your contributions!