diagnostics_channel.boundedChannel(nameOrChannels)


稳定性: 1 - 实验性

为给定的通道创建一个 BoundedChannel 封装器。如果提供了名称,则相应的通道将以 tracing:${name}:${eventType} 的形式创建,其中 eventTypestartend

🌐 Creates a BoundedChannel wrapper for the given channels. If a name is given, the corresponding channels will be created in the form of tracing:${name}:${eventType} where eventType is start or end.

BoundedChannelTracingChannel 的简化版本,仅跟踪同步操作。它仅具有 startend 事件,没有 asyncStartasyncEnderror 事件,因此适合跟踪不涉及异步延续或错误处理的操作。

🌐 A BoundedChannel is a simplified version of TracingChannel that only traces synchronous operations. It only has start and end events, without asyncStart, asyncEnd, or error events, making it suitable for tracing operations that don't involve asynchronous continuations or error handling.

import { boundedChannel, channel } from 'node:diagnostics_channel';

const wc = boundedChannel('my-operation');

// or...

const wc2 = boundedChannel({
  start: channel('tracing:my-operation:start'),
  end: channel('tracing:my-operation:end'),
});const { boundedChannel, channel } = require('node:diagnostics_channel');

const wc = boundedChannel('my-operation');

// or...

const wc2 = boundedChannel({
  start: channel('tracing:my-operation:start'),
  end: channel('tracing:my-operation:end'),
});