@@ -266,6 +266,91 @@ const channelsByCollection = diagnostics_channel.tracingChannel({
266266});
267267```
268268
269+ #### ` diagnostics_channel.syncTracingChannel(nameOrChannels) `
270+
271+ <!-- YAML
272+ added:
273+ - REPLACEME
274+ -->
275+
276+ > Stability: 1 - Experimental
277+
278+ * ` nameOrChannels ` {string|SyncTracingChannel|Object} Channel name or
279+ object containing the ` start ` , ` end ` , and ` error ` channels
280+ * Returns: {SyncTracingChannel}
281+
282+ Creates a [ ` SyncTracingChannel ` ] [ ] wrapper. Named construction creates channels
283+ using ` tracing:${name}:start ` , ` tracing:${name}:end ` , and
284+ ` tracing:${name}:error ` .
285+
286+ #### ` diagnostics_channel.callbackTracingChannel(nameOrChannels) `
287+
288+ <!-- YAML
289+ added:
290+ - REPLACEME
291+ -->
292+
293+ > Stability: 1 - Experimental
294+
295+ * ` nameOrChannels ` {string|CallbackTracingChannel|Object} Channel name or
296+ object containing the ` asyncStart ` , ` asyncEnd ` , and ` error ` channels
297+ * Returns: {CallbackTracingChannel}
298+
299+ Creates a [ ` CallbackTracingChannel ` ] [ ] wrapper. Named construction creates
300+ channels using ` tracing:${name}:asyncStart ` , ` tracing:${name}:asyncEnd ` , and
301+ ` tracing:${name}:error ` .
302+
303+ #### ` diagnostics_channel.promiseTracingChannel(nameOrChannels) `
304+
305+ <!-- YAML
306+ added:
307+ - REPLACEME
308+ -->
309+
310+ > Stability: 1 - Experimental
311+
312+ * ` nameOrChannels ` {string|PromiseTracingChannel|Object} Channel name or object
313+ containing the ` asyncStart ` , ` asyncEnd ` , and ` error ` channels
314+ * Returns: {PromiseTracingChannel}
315+
316+ Creates a [ ` PromiseTracingChannel ` ] [ ] wrapper. Named construction creates
317+ channels using ` tracing:${name}:asyncStart ` , ` tracing:${name}:asyncEnd ` , and
318+ ` tracing:${name}:error ` .
319+
320+ #### ` diagnostics_channel.syncIteratorTracingChannel(nameOrChannels) `
321+
322+ <!-- YAML
323+ added:
324+ - REPLACEME
325+ -->
326+
327+ > Stability: 1 - Experimental
328+
329+ * ` nameOrChannels ` {string|SyncIteratorTracingChannel|Object} Channel name or
330+ object containing the ` yield ` , ` return ` , and ` error ` channels
331+ * Returns: {SyncIteratorTracingChannel}
332+
333+ Creates a [ ` SyncIteratorTracingChannel ` ] [ ] wrapper. Named construction creates
334+ channels using ` tracing:${name}:syncYield ` , ` tracing:${name}:return ` , and
335+ ` tracing:${name}:error ` .
336+
337+ #### ` diagnostics_channel.asyncIteratorTracingChannel(nameOrChannels) `
338+
339+ <!-- YAML
340+ added:
341+ - REPLACEME
342+ -->
343+
344+ > Stability: 1 - Experimental
345+
346+ * ` nameOrChannels ` {string|AsyncIteratorTracingChannel|Object} Channel name or
347+ object containing the ` yield ` , ` return ` , and ` error ` channels
348+ * Returns: {AsyncIteratorTracingChannel}
349+
350+ Creates an [ ` AsyncIteratorTracingChannel ` ] [ ] wrapper. Named construction creates
351+ channels using ` tracing:${name}:asyncYield ` , ` tracing:${name}:return ` , and
352+ ` tracing:${name}:error ` .
353+
269354``` cjs
270355const diagnostics_channel = require (' node:diagnostics_channel' );
271356
@@ -754,7 +839,34 @@ simplify the process of producing events for tracing application flow.
754839[ ` diagnostics_channel.tracingChannel() ` ] [ ] is used to construct a
755840` TracingChannel ` . As with ` Channel ` it is recommended to create and reuse a
756841single ` TracingChannel ` at the top-level of the file rather than creating them
757- dynamically.
842+ dynamically. ` TracingChannel ` remains the aggregate compatibility wrapper for
843+ the original tracing channels.
844+
845+ #### ` tracingChannel.wrap(fn[, options]) `
846+
847+ <!-- YAML
848+ added:
849+ - REPLACEME
850+ -->
851+
852+ * ` fn ` {Function} Function to wrap
853+ * ` options ` {Object}
854+ * ` context ` {Object|Function} Context object or per-call context builder
855+ * ` wrapArgs ` {Function} Rewrite arguments before the call
856+ * ` mapResult ` {Function} Transform the immediate return value
857+ * Returns: {Function} Wrapped function
858+
859+ Wrap a function once and reuse the wrapped callable across multiple invocations.
860+ This is the recommended API for composing tracing behavior. The ` context `
861+ option may be either a plain object or a builder function. If ` context ` is an
862+ object, that same object is published for each operation. If ` context ` is a
863+ function, it is called once per invocation with the wrapped receiver as ` this `
864+ and the original arguments. ` wrapArgs ` and ` mapResult ` run inside the
865+ synchronous trace, so errors thrown from either are treated as call errors.
866+
867+ This method is intended to compose the specialized tracers. For example,
868+ ` wrapArgs ` can use ` callbackTracingChannel.wrapArgs() ` and ` mapResult ` can use
869+ ` promiseTracingChannel.wrap() ` or one of the iterator wrappers.
758870
759871#### ` tracingChannel.subscribe(subscribers) `
760872
@@ -1419,6 +1531,91 @@ is automatically published when disposal occurs at the end of the block. All
14191531events share the same context object, which can be extended with additional
14201532properties like ` result ` during scope execution.
14211533
1534+ ### Class: ` SyncTracingChannel `
1535+
1536+ > Stability: 1 - Experimental
1537+
1538+ ` SyncTracingChannel ` publishes ` start ` , ` end ` , and ` error ` events around the
1539+ synchronous call boundary of a wrapped function.
1540+
1541+ #### ` syncTracingChannel.wrap(fn[, options]) `
1542+
1543+ * ` fn ` {Function} Function to wrap
1544+ * ` options ` {Object}
1545+ * ` context ` {Object|Function} Context object or per-call context builder
1546+ * ` wrapArgs ` {Function} Rewrite arguments before the call
1547+ * ` mapResult ` {Function} Transform the immediate return value
1548+ * Returns: {Function} Wrapped function
1549+
1550+ ### Class: ` CallbackTracingChannel `
1551+
1552+ > Stability: 1 - Experimental
1553+
1554+ ` CallbackTracingChannel ` wraps callback functions and callback arguments using
1555+ ` asyncStart ` , ` asyncEnd ` , and ` error ` .
1556+
1557+ #### ` callbackTracingChannel.wrap(callback[, options]) `
1558+
1559+ * ` callback ` {Function} Callback to wrap
1560+ * ` options ` {Object}
1561+ * ` context ` {Object|Function} Context object or callback-time context builder
1562+ * ` mapOutcome ` {Function} Map callback arguments to ` { error, result } `
1563+ * Returns: {Function} Wrapped callback
1564+
1565+ #### ` callbackTracingChannel.wrapArgs(args, index[, options]) `
1566+
1567+ * ` args ` {Array} Arguments array
1568+ * ` index ` {number} Index of the callback argument
1569+ * ` options ` {Object}
1570+ * ` context ` {Object|Function} Context object or callback-time context builder
1571+ * ` mapOutcome ` {Function} Map callback arguments to ` { error, result } `
1572+ * Returns: {Array} A shallow copy of ` args ` with the callback replaced
1573+
1574+ ### Class: ` PromiseTracingChannel `
1575+
1576+ > Stability: 1 - Experimental
1577+
1578+ ` PromiseTracingChannel ` instruments a thenable or promise that has already been
1579+ produced and publishes ` asyncStart ` , ` asyncEnd ` , and ` error ` on settlement.
1580+
1581+ #### ` promiseTracingChannel.wrap(value[, options]) `
1582+
1583+ * ` value ` {any} Promise or thenable to wrap
1584+ * ` options ` {Object}
1585+ * ` context ` {Object|Function} Context object or context builder
1586+ * ` mapResult ` {Function} Transform the fulfilled value
1587+ * Returns: {any} The original value, or the result of calling ` .then(...) `
1588+
1589+ ### Class: ` SyncIteratorTracingChannel `
1590+
1591+ > Stability: 1 - Experimental
1592+
1593+ ` SyncIteratorTracingChannel ` instruments a synchronous iterator and publishes
1594+ ` yield ` , ` return ` , and ` error ` events for ` next() ` , ` return() ` , and ` throw() ` .
1595+
1596+ #### ` syncIteratorTracingChannel.wrap(iterator[, options]) `
1597+
1598+ * ` iterator ` {Object} Iterator to wrap
1599+ * ` options ` {Object}
1600+ * ` context ` {Object|Function} Context object or context builder
1601+ * ` mapResult ` {Function} Transform the produced ` IteratorResult `
1602+ * Returns: {Object} Wrapped iterator
1603+
1604+ ### Class: ` AsyncIteratorTracingChannel `
1605+
1606+ > Stability: 1 - Experimental
1607+
1608+ ` AsyncIteratorTracingChannel ` instruments an asynchronous iterator and publishes
1609+ ` yield ` , ` return ` , and ` error ` events for ` next() ` , ` return() ` , and ` throw() ` .
1610+
1611+ #### ` asyncIteratorTracingChannel.wrap(iterator[, options]) `
1612+
1613+ * ` iterator ` {Object} Async iterator to wrap
1614+ * ` options ` {Object}
1615+ * ` context ` {Object|Function} Context object or context builder
1616+ * ` mapResult ` {Function} Transform the produced ` IteratorResult `
1617+ * Returns: {Object} Wrapped iterator
1618+
14221619### TracingChannel Channels
14231620
14241621A TracingChannel is a collection of several diagnostics\_ channels representing
@@ -1914,8 +2111,13 @@ Emitted when a new thread is created.
19142111[ BoundedChannel Channels ] : #boundedchannel-channels
19152112[ TracingChannel Channels ] : #tracingchannel-channels
19162113[ `'uncaughtException'` ] : process.md#event-uncaughtexception
2114+ [ `AsyncIteratorTracingChannel` ] : #class-asynciteratortracingchannel
19172115[ `BoundedChannel` ] : #class-boundedchannel
19182116[ `TracingChannel` ] : #class-tracingchannel
2117+ [ `CallbackTracingChannel` ] : #class-callbacktracingchannel
2118+ [ `PromiseTracingChannel` ] : #class-promisetracingchannel
2119+ [ `SyncIteratorTracingChannel` ] : #class-synciteratortracingchannel
2120+ [ `SyncTracingChannel` ] : #class-synctracingchannel
19192121[ `asyncEnd` event ] : #asyncendevent
19202122[ `asyncStart` event ] : #asyncstartevent
19212123[ `boundedChannel.withScope(context)` ] : #boundedchannelwithscopecontext
0 commit comments