Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sentry/opentelemetry

Package Overview
Dependencies
Maintainers
11
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/opentelemetry

Official Sentry utilities for OpenTelemetry

  • 7.120.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
decreased by-11.17%
Maintainers
11
Weekly downloads
 
Created
Source

Sentry

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.

FAQs

Package last updated on 05 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc