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


稳定性: 1 - 实验性

  • fn <Function> 用于封装跟踪的函数
  • context <Object> 共享对象,用于关联事件
  • thisArg <any> 用于函数调用的接收对象
  • ...args <any> 可选参数,传递给函数
  • 返回值:<any> 给定函数的返回值

跟踪一个同步函数调用。这将始终在执行期间产生 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',
});