tracingChannel.traceSync(fn[, context[, thisArg[, ...args]]])


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

  • fn <Function> 环绕轨迹的函数

    ¥fn <Function> Function to wrap a trace around

  • context <Object> 通过共享对象关联事件

    ¥context <Object> Shared object to correlate events through

  • thisArg <any> 用于函数调用的接收器

    ¥thisArg <any> The receiver to be used for the function call

  • ...args <any> 传递给函数的可选参数

    ¥...args <any> Optional arguments to pass to the function

  • 返回:<any> 给定函数的返回值

    ¥Returns: <any> The return value of the given function

跟踪同步函数调用。这将始终在执行过程中产生 start 事件end 事件,如果给定的函数抛出错误,则可能会产生 error 事件。这将在 start 通道上使用 channel.runStores(context, ...) 运行给定函数,确保所有事件都应设置任何绑定存储以匹配此跟踪上下文。

¥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.

import diagnostics_channel from 'node:diagnostics_channel';

const channels = diagnostics_channel.tracingChannel('my-channel');

channels.traceSync(() => {
  // Do something
}, {
  some: 'thing',
});const diagnostics_channel = require('node:diagnostics_channel');

const channels = diagnostics_channel.tracingChannel('my-channel');

channels.traceSync(() => {
  // Do something
}, {
  some: 'thing',
});