import type { SpanInfo } from "./types.mjs"; /** * Called once per completed traced operation with the span info (derived from * the completed payload, falling back to the start-time payload for `onStart` * subscriptions), the operation start time (unix nanoseconds, as an OTLP * `*UnixNano` string), the operation's error (`undefined` when it succeeded) * and the state returned by `onStart` (`undefined` without one). A sink turns * this into whatever its platform consumes — an OTLP export, a log line, a * platform span, … */ export type SpanSink = (info: SpanInfo, startTimeUnixNano: string, error: unknown, state: S | undefined) => void; export interface SubscribeTracedChannelsOptions { /** * Called synchronously when a traced operation starts, inside its execution * context — where platform span APIs like Cloudflare's `enterSpan` must be * called. Returned state is handed back to `onSpan` at completion. */ onStart?: (info: SpanInfo) => S | undefined; } /** * Subscribes to the tracing channels declared in `TRACED_CHANNELS` (produced by * h3, srvx, unstorage, …) and invokes `onSpan` once per traced operation: * normally at `asyncEnd`, or at `end` when the traced function threw * synchronously (`tracePromise` never publishes `asyncEnd` in that case). * * A `tracingChannel()` publishes to plain named channels * (`tracing::start`, `tracing::asyncEnd`, …). Subscribing to those * names directly — rather than wrapping `tracingChannel` — needs no global patch * and works regardless of when the producer creates the channel: `subscribe` * registers against the name whether the channel exists yet or not. Channels * absent from `TRACED_CHANNELS` are never observed. * * A no-op when `node:diagnostics_channel` is unavailable (non-Node runtimes). */ export declare function subscribeTracedChannels(onSpan: SpanSink, options?: SubscribeTracedChannelsOptions): void;