TracingChannel
[<Interface>]
type TracingChannel<'StoreType, 'ContextType> =
abstract member asyncEnd: Channel<'StoreType,'ContextType> with get, set
abstract member asyncStart: Channel<'StoreType,'ContextType> with get, set
abstract member end: Channel<'StoreType,'ContextType> with get, set
abstract member error: Channel<'StoreType,'ContextType> with get, set
abstract member hasSubscribers: bool
abstract member start: Channel<'StoreType,'ContextType> with get, set
static member Create<'Args, 'Result, 'ThisArg> (start: Channel<'StoreType,'ContextType>, end: Channel<'StoreType,'ContextType>, asyncStart: Channel<'StoreType,'ContextType>, asyncEnd: Channel<'StoreType,'ContextType>, error: Channel<'StoreType,'ContextType>, subscribe: TracingChannelSubscribers<'ContextType> -> unit, unsubscribe: TracingChannelSubscribers<'ContextType> -> unit, traceSync: Func<('Args -> 'Result),'ContextType option,'ThisArg option,'Args,'Result>, tracePromise: Func<('Args -> Promise<'Result>),'ContextType option,'ThisArg option,'Args,Promise<'Result>>, traceCallback: Func<('Args -> 'Result),float option,'ContextType option,'ThisArg option,'Args,'Result>, hasSubscribers: bool) : TracingChannel<'StoreType,'ContextType>
abstract member subscribe (subscribers: TracingChannelSubscribers<'ContextType>) : unit
abstract member traceCallback<'ThisArg, 'Args, 'Result> (fn: 'Args -> 'Result, position: float option, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : 'Result
abstract member tracePromise<'ThisArg, 'Args, 'Result> (fn: 'Args -> Promise<'Result>, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : Promise<'Result>
abstract member traceSync<'ThisArg, 'Args, 'Result> (fn: 'Args -> 'Result, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : 'Result
abstract member unsubscribe (subscribers: TracingChannelSubscribers<'ContextType>) : unit| Assembly | Xantham.Fable.Node |
| Implements | TracingChannelCollection<obj,obj> |
| Attributes | [<Interface>] |
The class TracingChannel is a collection of TracingChannel Channels which together express a single traceable action. It is used to formalize and simplify the process of producing events for tracing application flow. tracingChannel is used to construct a TracingChannel. As with Channel it is recommended to create and reuse a single TracingChannel at the top-level of the file rather than creating them dynamically.
@since v19.9.0
Properties
abstract member asyncEnd: Channel<'StoreType,'ContextType> with get, setabstract member asyncStart: Channel<'StoreType,'ContextType> with get, setabstract member end: Channel<'StoreType,'ContextType> with get, setabstract member error: Channel<'StoreType,'ContextType> with get, setabstract member hasSubscribers: bool
abstract member hasSubscribers: booltrue if any of the individual channels has a subscriber, false if not.
This is a helper method available on a TracingChannel instance to check if any of the TracingChannel Channels have subscribers. A true is returned if any of them have at least one subscriber, a false is returned otherwise.
const diagnostics_channel = require('node:diagnostics_channel');
const channels = diagnostics_channel.tracingChannel('my-channel');
if (channels.hasSubscribers) {
// Do something
}
@since v22.0.0, v20.13.0
abstract member start: Channel<'StoreType,'ContextType> with get, setMethods
static member Create<'Args, 'Result, 'ThisArg> (start: Channel<'StoreType,'ContextType>, end: Channel<'StoreType,'ContextType>, asyncStart: Channel<'StoreType,'ContextType>, asyncEnd: Channel<'StoreType,'ContextType>, error: Channel<'StoreType,'ContextType>, subscribe: TracingChannelSubscribers<'ContextType> -> unit, unsubscribe: TracingChannelSubscribers<'ContextType> -> unit, traceSync: Func<('Args -> 'Result),'ContextType option,'ThisArg option,'Args,'Result>, tracePromise: Func<('Args -> Promise<'Result>),'ContextType option,'ThisArg option,'Args,Promise<'Result>>, traceCallback: Func<('Args -> 'Result),float option,'ContextType option,'ThisArg option,'Args,'Result>, hasSubscribers: bool) : TracingChannel<'StoreType,'ContextType>abstract member subscribe (subscribers: TracingChannelSubscribers<'ContextType>) : unit
abstract member subscribe (subscribers: TracingChannelSubscribers<'ContextType>) : unitHelper to subscribe a collection of functions to the corresponding channels. This is the same as calling channel.subscribe(onMessage) on each channel individually.
import diagnostics_channel from 'node:diagnostics_channel';
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.subscribe({
start(message) {
// Handle start message
},
end(message) {
// Handle end message
},
asyncStart(message) {
// Handle asyncStart message
},
asyncEnd(message) {
// Handle asyncEnd message
},
error(message) {
// Handle error message
},
});
@since v19.9.0
| Parameter | |
|---|---|
subscribers | Set of TracingChannel Channels subscribers |
abstract member traceCallback<'ThisArg, 'Args, 'Result> (fn: 'Args -> 'Result, position: float option, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : 'Result
abstract member traceCallback<'ThisArg, 'Args, 'Result> (fn: 'Args -> 'Result, position: float option, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : 'ResultTrace a callback-receiving function call. This will always produce a start event and end event around the synchronous portion of the function execution, and will produce a asyncStart event and asyncEnd event around the callback execution. It may also produce an error event if the given function throws an error or the returned promise rejects. This will run the given function using channel.runStores(context, ...) on the start channel which ensures all events should have any bound stores set to match this trace context.
The position will be -1 by default to indicate the final argument should be used as the callback.
import diagnostics_channel from 'node:diagnostics_channel';
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.traceCallback((arg1, callback) => {
// Do something
callback(null, 'result');
}, 1, {
some: 'thing',
}, thisArg, arg1, callback);
The callback will also be run with channel.runStores(context, ...) which enables context loss recovery in some cases.
To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
import diagnostics_channel from 'node:diagnostics_channel';
import { AsyncLocalStorage } from 'node:async_hooks';
const channels = diagnostics_channel.tracingChannel('my-channel');
const myStore = new AsyncLocalStorage();
// The start channel sets the initial store data to something
// and stores that store data value on the trace context object
channels.start.bindStore(myStore, (data) => {
const span = new Span(data);
data.span = span;
return span;
});
// Then asyncStart can restore from that data it stored previously
channels.asyncStart.bindStore(myStore, (data) => {
return data.span;
});
@since v19.9.0
| Parameter | |
|---|---|
fn | callback using function to wrap a trace around |
position | Zero-indexed argument position of expected callback |
context | Shared object to correlate trace events through |
thisArg | The receiver to be used for the function call |
args | Optional arguments to pass to the function |
Returns. The return value of the given function
abstract member tracePromise<'ThisArg, 'Args, 'Result> (fn: 'Args -> Promise<'Result>, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : Promise<'Result>
abstract member tracePromise<'ThisArg, 'Args, 'Result> (fn: 'Args -> Promise<'Result>, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : Promise<'Result>Trace a promise-returning function call. This will always produce a start event and end event around the synchronous portion of the function execution, and will produce an asyncStart event and asyncEnd event when a promise continuation is reached. It may also produce an error event if the given function throws an error or the returned promise rejects. This will run the given function using channel.runStores(context, ...) on the start channel which ensures all events should have any bound stores set to match this trace context.
To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
import diagnostics_channel from 'node:diagnostics_channel';
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.tracePromise(async () => {
// Do something
}, {
some: 'thing',
});
@since v19.9.0
| Parameter | |
|---|---|
fn | Promise-returning function to wrap a trace around |
context | Shared object to correlate trace events through |
thisArg | The receiver to be used for the function call |
args | Optional arguments to pass to the function |
Returns. Chained from promise returned by the given function
abstract member traceSync<'ThisArg, 'Args, 'Result> (fn: 'Args -> 'Result, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : 'Result
abstract member traceSync<'ThisArg, 'Args, 'Result> (fn: 'Args -> 'Result, context: 'ContextType option, thisArg: 'ThisArg option, args: 'Args) : 'ResultTrace a synchronous function call. This will always produce a start event and end event around the execution and may produce an error event if the given function throws an error. This will run the given function using channel.runStores(context, ...) on the start channel which ensures all events should have any bound stores set to match this trace context.
To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
import diagnostics_channel from 'node:diagnostics_channel';
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.traceSync(() => {
// Do something
}, {
some: 'thing',
});
@since v19.9.0
| Parameter | |
|---|---|
fn | Function to wrap a trace around |
context | Shared object to correlate events through |
thisArg | The receiver to be used for the function call |
args | Optional arguments to pass to the function |
Returns. The return value of the given function
abstract member unsubscribe (subscribers: TracingChannelSubscribers<'ContextType>) : unit
abstract member unsubscribe (subscribers: TracingChannelSubscribers<'ContextType>) : unitHelper to unsubscribe a collection of functions from the corresponding channels. This is the same as calling channel.unsubscribe(onMessage) on each channel individually.
import diagnostics_channel from 'node:diagnostics_channel';
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.unsubscribe({
start(message) {
// Handle start message
},
end(message) {
// Handle end message
},
asyncStart(message) {
// Handle asyncStart message
},
asyncEnd(message) {
// Handle asyncEnd message
},
error(message) {
// Handle error message
},
});
@since v19.9.0
| Parameter | |
|---|---|
subscribers | Set of TracingChannel Channels subscribers |
Returns. true if all handlers were successfully unsubscribed, and false otherwise.