TracingChannel 通道


【TracingChannel Channels】

TracingChannel 是多个 diagnostics_channel 的集合,表示单个可追踪操作执行周期中的特定点。其行为被分为五个 diagnostics_channel,包括 startendasyncStartasyncEnderror。单个可追踪操作将在所有事件之间共享相同的事件对象,这对于通过 weakmap 管理关联关系非常有用。

【A TracingChannel is a collection of several diagnostics_channels representing specific points in the execution lifecycle of a single traceable action. The behavior is split into five diagnostics_channels consisting of start, end, asyncStart, asyncEnd, and error. A single traceable action will share the same event object between all events, this can be helpful for managing correlation through a weakmap.】

当任务“完成”时,这些事件对象将会扩展包含 resulterror 的值。对于同步任务,result 将是返回值,而 error 则是函数中抛出的任何异常。对于基于回调的异步函数,result 将是回调的第二个参数,而 error 要么是在 end 事件中可见的抛出错误,要么是在 asyncStartasyncEnd 事件中的第一个回调参数。

【These event objects will be extended with result or error values when the task "completes". In the case of a synchronous task the result will be the return value and the error will be anything thrown from the function. With callback-based async functions the result will be the second argument of the callback while the error will either be a thrown error visible in the end event or the first callback argument in either of the asyncStart or asyncEnd events.】

为了确保只形成正确的跟踪图,事件只有在跟踪开始前存在订阅者时才应发布。在跟踪开始后添加的订阅不应接收该跟踪的未来事件,只会看到未来的跟踪。

【To ensure only correct trace graphs are formed, events should only be published if subscribers are present prior to starting the trace. Subscriptions which are added after the trace begins should not receive future events from that trace, only future traces will be seen.】

跟踪通道应遵循以下命名模式:

【Tracing channels should follow a naming pattern of:】

  • tracing:模块.类.方法:starttracing:模块.函数:start
  • tracing:模块.类.方法:endtracing:模块.函数:end
  • tracing:模块.类.方法:asyncStarttracing:模块.函数:asyncStart
  • tracing:模块.类.方法:asyncEndtracing:模块.函数:asyncEnd
  • tracing:模块.类.方法:错误tracing:模块.函数:错误