All files / packages/telemetry/src context.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                              5x     1048x    
import { AsyncLocalStorage } from 'node:async_hooks'
 
import type { Span } from '@opentelemetry/api'
 
/**
 * Active subscriber span, propagated across async continuations via
 * `tracingChannel.bindStore`. We keep our own ALS instead of reusing
 * OTel's context because channel handlers are discrete events — there's no
 * function for `context.with(ctx, fn)` to wrap, and `enterWith` isn't part
 * of OTel's public API.
 *
 * Stored value is `Span | undefined` because the bindStore transform may
 * return `undefined` when span creation throws — children then transparently
 * fall back to `context.active()` instead of seeing a poisoned parent.
 */
export let spanStorage = new AsyncLocalStorage<Span | undefined>()
 
export function getActiveSubscriberSpan(): Span | undefined {
	return spanStorage.getStore()
}