The main OpenTelemetry API interface that provides access to all OpenTelemetry functionality. This interface extends the IOTelTracerProvider and serves as the entry point for OpenTelemetry operations.

// Get a tracer from the API instance
const tracer = otelApi.getTracer("my-component");

// Create a span
const span = tracer.startSpan("operation");

// Access context manager
const currentContext = otelApi.context.active();

// Access trace API
const activeSpan = otelApi.trace.getActiveSpan();

3.4.0

interface IOTelApi {
    cfg: IOTelConfig;
    forceFlush?: (() => void | IPromise<void>);
    getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer;
    host: ITraceHost<IConfiguration>;
    shutdown?: (() => void | IPromise<void>);
    trace: ITraceApi;
}

Hierarchy (view full)

Properties

The configuration object that contains all OpenTelemetry-specific settings. This includes tracing configuration, error handlers, and other OpenTelemetry options.

Changes to this configuration after initialization may not take effect until the next telemetry operation, depending on the implementation.

forceFlush?: (() => void | IPromise<void>)

Forces the tracer provider to flush any buffered data.

Type declaration

    • (): void | IPromise<void>
    • Returns void | IPromise<void>

      A promise that resolves when the flush is complete.

The current ITraceHost instance for this IOTelApi instance, this is effectively the OpenTelemetry ContextAPI instance without the static methods.

The ContextManager instance

shutdown?: (() => void | IPromise<void>)

Shuts down the tracer provider and releases any resources.

Type declaration

    • (): void | IPromise<void>
    • Returns void | IPromise<void>

      A promise that resolves when the shutdown is complete.

trace: ITraceApi

The current ITraceApi instance for this IOTelApi instance, this is effectively the OpenTelemetry TraceAPI instance without the static methods.

The current ITraceApi instance

Methods

  • Returns a Tracer, creating one if one with the given name and version is not already created. This may return

    • The same Tracer instance if one has already been created with the same name and version
    • A new Tracer instance if one has not already been created with the same name and version
    • A non-operational Tracer if the provider is not operational

    Parameters

    • name: string

      The name of the tracer or instrumentation library.

    • Optionalversion: string

      The version of the tracer or instrumentation library.

    • Optionaloptions: IOTelTracerOptions

      The options of the tracer or instrumentation library.

    Returns IOTelTracer

    Tracer A Tracer with the given name and version