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.21.0
Important Changes
- Alpha release of Official Cloudflare SDK
- feat(cloudflare): Add
withSentry
method (#13025) - feat(cloudflare): Add cloudflare sdk scaffolding (#12953)
- feat(cloudflare): Add basic cloudflare package and tests (#12861)
This release contains the alpha version of @sentry/cloudflare
, our SDK for the
Cloudflare Workers JavaScript Runtime! For details on how to use it,
please see the README. Any feedback/bug reports are greatly appreciated, please
reach out on GitHub.
Please note that only Cloudflare Workers are tested and supported - official Cloudflare Pages support will come in an
upcoming release.
Other Changes
- feat(feedback): Make cropped screenshot area draggable (#13071)
- feat(core): Adapt spans for client-side fetch to streaming responses (#12723)
- feat(core): Capture # of dropped spans through
beforeSendTransaction
(#13022) - feat(deps): bump
@opentelemetry/instrumentation-aws-sdk
from 0.43.0 to 0.43.1 (#13089) - feat(deps): bump
@opentelemetry/instrumentation-express
from 0.41.0 to 0.41.1 (#13090) - feat(nestjs): Automatic instrumentation of nestjs middleware (#13065)
- feat(node): Upgrade
import-in-the-middle
to 1.11.0 (#13107) - feat(nuxt): Add connected tracing meta tags (#13098)
- feat(nuxt): Add vue-router instrumentation (#13054)
- feat(solidstart): Add server action instrumentation helper (#13035)
- fix(feedback): Ensure pluggable feedback CDN bundle is correctly built (#13081)
- fix(nextjs): Only delete clientside bundle source maps with
sourcemaps.deleteFilesAfterUpload
(#13102) - fix(node): Improve OTEL validation logic (#13079)