interface TracerHost
Since 0.2.0

The host seam returned by loadOtelTracerProvider.

Consumers (the plugin factory, tests) can supply a pre-built host via tracerProviderFactory to bypass the lazy OTel import.

Properties

Since 0.2.0
readonly
optional
otelProvider: unknown

The underlying OTel TracerProvider; undefined for noop/custom hosts (instrumentations then no-op).

Methods

startSpan(
name: string,
options?: { kind?: number; attributes?: Record<string, unknown>; parentContext?: TelemetryContext; }
): unknown

Starts a new span.

optional
activate<T>(
span: unknown,
fn: () => Promise<T>
): Promise<T>

Runs work with the supplied span as the active OTel span, when supported.

Since 0.5.0
optional
activeSpanContext(): SpanContext | undefined

Reports the identifiers of the span the OTel context currently holds active, or undefined when nothing is active.

This is the read that lets a signal emitted OUTSIDE a withSpan call — a log record, above all — name the trace it belongs to (X34-2). It cannot be answered from ITelemetryService alone, which hands its span only to its own callback, so the host is where it lives.

Optional, and paired with activate: a host with no registered context manager never has an active span, so it omits this member rather than answering undefined forever. Omitted means "this host cannot see"; undefined from an implemented member means "nothing is running".

Extracts a context from incoming headers (for traceparent propagation).

injectContext(context: TelemetryContext): Record<string, string>

Injects a context into outgoing headers.

shutdown(): Promise<void>

Shuts down the provider and flushes pending spans.

forceFlush(): Promise<void>

Forces flush of pending spans.

Usage

import { type TracerHost } from "telemetry-plugin/src/index.ts";