@sentry/opentelemetry v7.113.0
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
# Or yarn
yarn add @sentry/opentelemetry
Note that @sentry/opentelemetry
depends on the following peer dependencies:
@opentelemetry/api
version1.0.0
or greater@opentelemetry/core
version1.0.0
or greater@opentelemetry/semantic-conventions
version1.0.0
or greater@opentelemetry/sdk-trace-base
version1.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:
- Setup the global hub for OpenTelemetry compatibility - ensure
setupGlobalHub()
is called before anything else! - Initialize Sentry, e.g.
@sentry/node
- make sure to setinstrumenter: 'otel'
in the SDKinit({})
! - 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 {
getCurrentHub,
setupGlobalHub,
SentryPropagator,
SentrySampler,
SentrySpanProcessor,
setupEventContextTrace,
wrapContextManagerClass,
setOpenTelemetryContextAsyncContextStrategy,
} from '@sentry/opentelemetry';
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
function setupSentry() {
setupGlobalHub();
Sentry.init({
dsn: 'xxx',
instrumenter: 'otel'
});
const client = getCurrentHub().getClient();
setupEventContextTrace(client);
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
});
provider.addSpanProcessor(new SentrySpanProcessor());
const SentryContextManager = wrapContextManagerClass(AsyncLocalStorageContextManager);
// Initialize the provider
provider.register({
propagator: new SentryPropagator(),
contextManager: new SentryContextManager(),
});
setOpenTelemetryContextAsyncContextStrategy();
}
A full setup example can be found in node-experimental.
Links
20 hours ago
3 days ago
9 days ago
9 days ago
10 days ago
10 days ago
14 days ago
15 days ago
16 days ago
18 days ago
18 days ago
22 days ago
25 days ago
25 days ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
7 months ago