method TracerHost.activeSpanContext
Since 0.5.0
TracerHost.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".

Return Type

SpanContext | undefined

The active span's identifiers, or undefined

Usage

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