tracingChannel.tracePromise(fn[, context[, thisArg[, ...args]]])
fn<Function> 用于在其上封装跟踪的返回 Promise 的函数context<Object> 用于关联跟踪事件的共享对象thisArg<any> 用于函数调用的接收器...args<any> 传递给函数的可选参数- 返回:<Promise> 从给定函数返回的承诺链接
跟踪返回 Promise 的函数调用。这将在函数执行的同步部分始终产生 start 事件 和 end 事件,并且在到达 Promise 延续时会产生 asyncStart 事件 和 asyncEnd 事件。如果给定的函数抛出错误或返回的 Promise 被拒绝,它也可能产生 error 事件。这将使用 start 通道上的 channel.runStores(context, ...) 运行给定函数,这确保所有事件的任何绑定存储都设置为匹配此跟踪上下文。
🌐 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.
import diagnostics_channel from 'node:diagnostics_channel';
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.tracePromise(async () => {
// Do something
}, {
some: 'thing',
});const diagnostics_channel = require('node:diagnostics_channel');
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.tracePromise(async () => {
// Do something
}, {
some: 'thing',
});