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

@opentelemetry/sdk-trace-base

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/sdk-trace-base

OpenTelemetry Tracing

  • 1.17.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.5M
decreased by-16.63%
Maintainers
3
Weekly downloads
 
Created

What is @opentelemetry/sdk-trace-base?

The @opentelemetry/sdk-trace-base package is part of the OpenTelemetry JavaScript SDK, which provides the core functionality for tracing. It allows developers to collect and export trace data to various backends for analysis and visualization. The package includes base classes and interfaces for implementing custom trace exporters, span processors, and configuration.

What are @opentelemetry/sdk-trace-base's main functionalities?

Basic Tracer Provider Setup

This code sets up a basic tracer provider with a simple span processor that exports spans to the console. It's the starting point for setting up OpenTelemetry tracing in an application.

const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { ConsoleSpanExporter } = require('@opentelemetry/tracing');

const provider = new BasicTracerProvider();
const consoleExporter = new ConsoleSpanExporter();
provider.addSpanProcessor(new SimpleSpanProcessor(consoleExporter));
provider.register();

Custom Span Processor

This code demonstrates how to create a custom span processor by extending the SpanProcessor class from the @opentelemetry/sdk-trace-base package. Developers can add custom logic for handling spans on start, on end, and during shutdown.

const { SpanProcessor } = require('@opentelemetry/sdk-trace-base');

class MySpanProcessor extends SpanProcessor {
  onStart(span) {
    // Custom logic for when a span starts.
  }

  onEnd(span) {
    // Custom logic for when a span ends.
  }

  shutdown() {
    // Custom logic for shutdown.
  }
}

Configuring a Tracer Provider

This code snippet shows how to configure a tracer provider with a specific span processor and exporter. It's a common pattern for initializing tracing in an application with OpenTelemetry.

const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');

const provider = new BasicTracerProvider();
const exporter = new ConsoleSpanExporter();
const processor = new SimpleSpanProcessor(exporter);

provider.addSpanProcessor(processor);
provider.register();

Other packages similar to @opentelemetry/sdk-trace-base

Keywords

FAQs

Package last updated on 10 Oct 2023

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