7.113.0 • Published 20 hours ago

@sentry/opentelemetry v7.113.0

Weekly downloads
-
License
MIT
Repository
github
Last release
20 hours ago

Official Sentry SDK for OpenTelemetry

npm version npm dm npm dt

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 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:

  1. Setup the global hub for OpenTelemetry compatibility - ensure setupGlobalHub() is called before anything else!
  2. Initialize Sentry, e.g. @sentry/node - make sure to set instrumenter: 'otel' in the SDK init({})!
  3. Call setupEventContextTrace(client)
  4. Add SentrySampler as sampler
  5. Add SentrySpanProcessor as span processor
  6. Add a context manager wrapped via wrapContextManagerClass
  7. Add SentryPropagator as propagator
  8. 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

7.113.0

20 hours ago

8.0.0-beta.5

3 days ago

7.112.2

9 days ago

8.0.0-beta.4

9 days ago

7.112.0

10 days ago

7.112.1

10 days ago

8.0.0-beta.3

14 days ago

7.111.0

15 days ago

8.0.0-beta.2

16 days ago

7.110.1

18 days ago

8.0.0-beta.1

18 days ago

7.110.0

22 days ago

8.0.0-alpha.9

25 days ago

8.0.0-alpha.8

25 days ago

7.109.0

1 month ago

8.0.0-alpha.7

1 month ago

8.0.0-alpha.5

1 month ago

7.108.0

1 month ago

8.0.0-alpha.3

2 months ago

8.0.0-alpha.4

2 months ago

7.107.0

2 months ago

7.106.1

2 months ago

7.106.0

2 months ago

8.0.0-alpha.2

2 months ago

8.0.0-alpha.1

2 months ago

7.105.0

2 months ago

7.104.0

2 months ago

7.103.0

2 months ago

7.102.1

2 months ago

7.102.0

2 months ago

7.101.1

3 months ago

7.101.0

3 months ago

7.100.1

3 months ago

7.100.0

3 months ago

7.99.0

3 months ago

7.96.0

3 months ago

7.97.0

3 months ago

7.98.0

3 months ago

7.95.0

3 months ago

7.94.0

3 months ago

7.94.1

3 months ago

7.93.0

4 months ago

7.92.0

4 months ago

7.91.0

4 months ago

7.90.0

4 months ago

7.89.0

5 months ago

7.88.0

5 months ago

7.87.0

5 months ago

7.86.0

5 months ago

7.85.0

5 months ago

7.84.0

5 months ago

7.83.0

5 months ago

7.82.0

5 months ago

7.81.1

5 months ago

7.81.0

5 months ago

7.80.2-alpha.1

6 months ago

7.80.2-alpha.0

6 months ago

7.80.1

6 months ago

7.80.0

6 months ago

7.79.0

6 months ago

7.78.0

6 months ago

7.77.0

6 months ago

7.76.0

6 months ago

7.75.1

6 months ago

7.75.0

6 months ago

7.74.2-alpha.1

6 months ago

7.74.2-alpha.0

7 months ago