traceSync

fun <ThisArg, Args : ReadonlyArray<Any?>> traceSync(fn: Function<Any?>, context: ContextType = definedExternally, thisArg: ThisArg = definedExternally, vararg args: Any?)(source)

Trace 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

Return

The return value of the given function

Parameters

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