Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@opentelemetry/sdk-trace-base
Advanced tools
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.
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();
The jaeger-client package is a Node.js client for Jaeger, a distributed tracing system. It provides similar functionality to @opentelemetry/sdk-trace-base, allowing developers to send trace data to a Jaeger backend. However, it is specific to Jaeger, whereas OpenTelemetry provides a more vendor-neutral approach.
This package is an OpenTracing-compatible tracer implementation for Zipkin in JavaScript. Like @opentelemetry/sdk-trace-base, it enables tracing and exporting trace data but is tailored for integration with Zipkin, a different distributed tracing system.
Lightstep's tracer library for JavaScript is designed to monitor and trace application performance. It is similar to @opentelemetry/sdk-trace-base in that it collects trace data, but it is specifically built to work with Lightstep's performance monitoring platform.
The tracing
module contains the foundation for all tracing SDKs of opentelemetry-js.
Used standalone, this module provides methods for manual instrumentation of code, offering full control over span creation for client-side JavaScript (browser) and Node.js.
It does not provide automated instrumentation of known libraries, context propagation for asynchronous invocations or distributed-context out-of-the-box.
For automated instrumentation for Node.js, please see @opentelemetry/sdk-trace-node.
npm install --save @opentelemetry/api
npm install --save @opentelemetry/sdk-trace-base
const opentelemetry = require('@opentelemetry/api');
const { BasicTracerProvider } = require('@opentelemetry/sdk-trace-base');
// To start a trace, you first need to initialize the Tracer provider.
// NOTE: The default OpenTelemetry tracer provider does not record any tracing information.
// Registering a working tracer provider allows the API methods to record traces.
new BasicTracerProvider().register();
// To create a span in a trace, we used the global singleton tracer to start a new span.
const span = opentelemetry.trace.getTracer('default').startSpan('foo');
// Set a span attribute
span.setAttribute('key', 'value');
// We must end the spans so they become available for exporting.
span.end();
Tracing configuration is a merge of user supplied configuration with both the default
configuration as specified in config.ts and an
environmentally configurable sampling (via OTEL_TRACES_SAMPLER
and OTEL_TRACES_SAMPLER_ARG
).
See examples/basic-tracer-node for an end-to-end example, including exporting created spans.
Apache 2.0 - See LICENSE for more information.
1.1.0
opentelemetry-resources
exporter-trace-otlp-http
, opentelemetry-core
instrumentation-http
opentelemetry-core
, opentelemetry-exporter-jaeger
exporter-trace-otlp-grpc
, exporter-trace-otlp-http
, exporter-trace-otlp-proto
, opentelemetry-context-async-hooks
, opentelemetry-context-zone-peer-dep
, opentelemetry-core
, opentelemetry-exporter-jaeger
, opentelemetry-exporter-zipkin
, opentelemetry-propagator-b3
, opentelemetry-propagator-jaeger
, opentelemetry-resources
, opentelemetry-sdk-trace-base
, opentelemetry-sdk-trace-node
, opentelemetry-sdk-trace-web
, opentelemetry-shim-opentracing
opentelemetry-sdk-trace-web
exporter-trace-otlp-http
, exporter-trace-otlp-proto
exporter-trace-otlp-grpc
, exporter-trace-otlp-http
, exporter-trace-otlp-proto
, opentelemetry-core
, opentelemetry-exporter-jaeger
, opentelemetry-sdk-trace-base
opentelemetry-propagator-jaeger
exporter-trace-otlp-grpc
, exporter-trace-otlp-http
, exporter-trace-otlp-proto
opentelemetry-context-zone-peer-dep
, opentelemetry-context-zone
, opentelemetry-core
, opentelemetry-exporter-zipkin
, opentelemetry-propagator-b3
, opentelemetry-resources
, opentelemetry-sdk-trace-base
, opentelemetry-sdk-trace-web
, opentelemetry-semantic-conventions
exporter-trace-otlp-grpc
, exporter-trace-otlp-http
, exporter-trace-otlp-proto
opentelemetry-sdk-trace-base
opentelemetry-core
opentelemetry-exporter-jaeger
opentelemetry-resources
opentelemetry-propagator-jaeger
opentelemetry-exporter-zipkin
, opentelemetry-sdk-trace-web
exporter-trace-otlp-grpc
opentelemetry-context-async-hooks
opentelemetry-context-async-hooks
, opentelemetry-sdk-trace-node
opentelemetry-sdk-trace-base
exporter-trace-otlp-http
, opentelemetry-context-zone-peer-dep
, opentelemetry-context-zone
, opentelemetry-core
, opentelemetry-exporter-zipkin
, opentelemetry-propagator-b3
, opentelemetry-resources
, opentelemetry-sdk-trace-base
, opentelemetry-sdk-trace-web
, opentelemetry-semantic-conventions
opentelemetry-core
exporter-trace-otlp-grpc
, exporter-trace-otlp-http
, exporter-trace-otlp-proto
, opentelemetry-exporter-jaeger
, opentelemetry-exporter-zipkin
, opentelemetry-propagator-b3
, opentelemetry-resources
, opentelemetry-sdk-trace-base
, opentelemetry-sdk-trace-web
, opentelemetry-semantic-conventions
exporter-trace-otlp-grpc
, exporter-trace-otlp-http
, exporter-trace-otlp-proto
, opentelemetry-context-async-hooks
, opentelemetry-context-zone-peer-dep
, opentelemetry-context-zone
, opentelemetry-core
, opentelemetry-exporter-jaeger
, opentelemetry-exporter-zipkin
, opentelemetry-propagator-b3
, opentelemetry-propagator-jaeger
, opentelemetry-resources
, opentelemetry-sdk-trace-base
, opentelemetry-sdk-trace-node
, opentelemetry-sdk-trace-web
, opentelemetry-semantic-conventions
, opentelemetry-shim-opentracing
, template
opentelemetry-context-async-hooks
, opentelemetry-context-zone-peer-dep
, opentelemetry-context-zone
, opentelemetry-core
, opentelemetry-exporter-jaeger
, opentelemetry-exporter-zipkin
, opentelemetry-propagator-b3
, opentelemetry-propagator-jaeger
, opentelemetry-resources
, opentelemetry-sdk-trace-base
, opentelemetry-sdk-trace-node
, opentelemetry-sdk-trace-web
, opentelemetry-semantic-conventions
, opentelemetry-shim-opentracing
opentelemetry-exporter-jaeger
, opentelemetry-exporter-zipkin
, opentelemetry-resources
, opentelemetry-semantic-conventions
opentelemetry-sdk-trace-web
FAQs
OpenTelemetry Tracing
The npm package @opentelemetry/sdk-trace-base receives a total of 6,295,815 weekly downloads. As such, @opentelemetry/sdk-trace-base popularity was classified as popular.
We found that @opentelemetry/sdk-trace-base demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.