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

@opentelemetry/sdk-trace-web

Package Overview
Dependencies
Maintainers
3
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/sdk-trace-web

OpenTelemetry Web Tracer

  • 1.28.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
471K
decreased by-18.94%
Maintainers
3
Weekly downloads
 
Created

What is @opentelemetry/sdk-trace-web?

@opentelemetry/sdk-trace-web is a package that provides OpenTelemetry tracing capabilities specifically for web applications. It allows developers to capture and export trace data from web applications, which can be used for performance monitoring, debugging, and observability.

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

Initialize Tracer

This code initializes a tracer provider for web applications, sets up a span processor to export spans to the console, and registers the provider. The tracer can then be used to create and manage spans.

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

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

const tracer = provider.getTracer('example-tracer-web');

Create and End a Span

This code demonstrates how to create a span, simulate some work with a timeout, and then end the span. Spans represent units of work and are used to measure the time taken for operations.

const span = tracer.startSpan('example-span');
// Simulate some work
setTimeout(() => {
  span.end();
}, 1000);

Add Attributes to a Span

This code shows how to add attributes to a span. Attributes are key-value pairs that provide additional context about the span.

const span = tracer.startSpan('example-span');
span.setAttribute('key', 'value');
span.end();

Add Events to a Span

This code demonstrates how to add events to a span. Events are time-stamped annotations that provide additional information about the span.

const span = tracer.startSpan('example-span');
span.addEvent('event-name', { 'key': 'value' });
span.end();

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

Keywords

FAQs

Package last updated on 18 Nov 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