Initialization
initOtel()
Manually initialize OpenTelemetry (called automatically byinit()).
OtelConfig
OpenTelemetry configuration
Example: Custom Configuration
shutdownOtel()
Shutdown OpenTelemetry and flush pending data.Distributed Tracing
getTracer()
Get the OpenTelemetry tracer instance.Tracer | null
OpenTelemetry tracer, or
null if OTel is disabledwithSpan()
Create and run a function within a new span.string
required
Span name
object
required
(span: Span) => Promise<T>
required
Async function to execute within the span
T
The function’s return value
Example: Custom Spans
Trace Context Propagation
The SDK automatically propagates W3C trace context across function calls:Context Extraction and Injection
Baggage
Baggage propagates key-value pairs across service boundaries.setBaggageEntry()
Set a baggage entry in the current context.getBaggageEntry()
Get a baggage entry from the current context.getAllBaggage()
Get all baggage entries.removeBaggageEntry()
Remove a baggage entry.Metrics
getMeter()
Get the OpenTelemetry meter instance for creating custom metrics.Meter | null
OpenTelemetry meter, or
null if OTel is disabledExample: Custom Metrics
Logging
getLogger()
Get the OpenTelemetry logger instance.Logger | null
OpenTelemetry logger, or
null if OTel is disabledExample: Direct Logging
Most applications should use the Context Logger instead. See Context API.
Instrumentation
Add custom instrumentations for automatic tracing of libraries:Environment Variables
Configure OpenTelemetry via environment variables:Best Practices
Add meaningful span attributes
Add meaningful span attributes
Use span events for important milestones
Use span events for important milestones
Use baggage for cross-cutting concerns
Use baggage for cross-cutting concerns
Create custom metrics for business events
Create custom metrics for business events