Tracing and diagnostics channels
A trace represents a related series of operations, often using span identifiers and parent relationships. Node diagnostics channels provide named in-process publication points for instrumentation. Create or obtain a channel, subscribe a listener and publish small structured records. Unsubscribe when the consumer is finished. Channel callbacks run synchronously, so expensive instrumentation can affect application latency. A trace model records parent/span identifiers and bounded attributes. OpenTelemetry adds standard context propagation, span lifecycle, sampling and exporters; the fixture does not install or export through OpenTelemetry. Do not confuse a channel event with a complete distributed trace. Do not include credentials in span attributes or make an observer perform unbounded synchronous work. Missing telemetry does not establish that a business operation never happened. Sources: https://nodejs.org/download/release/v22.16.0/docs/api/diagnostics_channel.html.
Formal Syntax & Structure
channel(name); channel.subscribe(listener); channel.publish(message); channel.unsubscribe(listener)Working Example
import {channel} from 'node:diagnostics_channel';import assert from 'node:assert/strict';const events=channel('bytemind.catalog.fixture');const received=[];const handler=message=>received.push(message.event);events.subscribe(handler);try{events.publish({event:'lookup',count:1});}finally{events.unsubscribe(handler);}events.publish({event:'ignored'});assert.deepEqual(received,['lookup']);console.log(received.join(','));