Diagnostics Channel#

安定性: 2 - 安定版

ソースコード: lib/diagnostics_channel.js

node:diagnostics_channel モジュールは、診断目的で任意のメッセージデータの報告を行う名前付きチャネルを作成するためのAPIを提供します。

以下の方法でアクセスできます。

import diagnostics_channel from 'node:diagnostics_channel';const diagnostics_channel = require('node:diagnostics_channel');

診断メッセージを報告したいモジュール作成者は、メッセージを報告するための1つまたは複数のトップレベルチャネルを作成することを意図しています。チャネルは実行時に取得することもできますが、追加のオーバーヘッドがあるため推奨されていません。チャネルは便宜上エクスポートできますが、名前がわかっていればどこからでも取得できます。

モジュールが他のモジュールが消費するための診断データを作成する場合は、使用されている名前付きチャネルとメッセージデータの構造に関するドキュメントを含めることをお勧めします。他のモジュールのデータとの衝突を避けるために、チャネル名は一般的にモジュール名を含める必要があります。

公開API#

概要#

以下は、公開APIの概要です。

import diagnostics_channel from 'node:diagnostics_channel';

// Get a reusable channel object
const channel = diagnostics_channel.channel('my-channel');

function onMessage(message, name) {
  // Received data
}

// Subscribe to the channel
diagnostics_channel.subscribe('my-channel', onMessage);

// Check if the channel has an active subscriber
if (channel.hasSubscribers) {
  // Publish data to the channel
  channel.publish({
    some: 'data',
  });
}

// Unsubscribe from the channel
diagnostics_channel.unsubscribe('my-channel', onMessage);const diagnostics_channel = require('node:diagnostics_channel');

// Get a reusable channel object
const channel = diagnostics_channel.channel('my-channel');

function onMessage(message, name) {
  // Received data
}

// Subscribe to the channel
diagnostics_channel.subscribe('my-channel', onMessage);

// Check if the channel has an active subscriber
if (channel.hasSubscribers) {
  // Publish data to the channel
  channel.publish({
    some: 'data',
  });
}

// Unsubscribe from the channel
diagnostics_channel.unsubscribe('my-channel', onMessage);
diagnostics_channel.hasSubscribers(name)#

名前付きチャネルにアクティブなサブスクライバがいるかどうかを確認します。送信したいメッセージの準備にコストがかかる場合に便利です。

このAPIはオプションですが、非常にパフォーマンスに敏感なコードからメッセージを公開しようとする場合に役立ちます。

import diagnostics_channel from 'node:diagnostics_channel';

if (diagnostics_channel.hasSubscribers('my-channel')) {
  // There are subscribers, prepare and publish message
}const diagnostics_channel = require('node:diagnostics_channel');

if (diagnostics_channel.hasSubscribers('my-channel')) {
  // There are subscribers, prepare and publish message
}
diagnostics_channel.channel(name)#

これは、名前付きチャネルに公開したいユーザーのための主要なエントリポイントです。公開時のオーバーヘッドを可能な限り削減するように最適化されたチャネルオブジェクトを作成します。

import diagnostics_channel from 'node:diagnostics_channel';

const channel = diagnostics_channel.channel('my-channel');const diagnostics_channel = require('node:diagnostics_channel');

const channel = diagnostics_channel.channel('my-channel');
diagnostics_channel.subscribe(name, onMessage)#

このチャネルを購読するメッセージハンドラを登録します。このメッセージハンドラは、チャネルにメッセージが公開されるたびに同期的に実行されます。メッセージハンドラでスローされたエラーは、'uncaughtException' をトリガーします。

import diagnostics_channel from 'node:diagnostics_channel';

diagnostics_channel.subscribe('my-channel', (message, name) => {
  // Received data
});const diagnostics_channel = require('node:diagnostics_channel');

diagnostics_channel.subscribe('my-channel', (message, name) => {
  // Received data
});
diagnostics_channel.unsubscribe(name, onMessage)#
  • name <string> | <symbol> チャネル名
  • onMessage <Function> 削除する前に登録されたハンドラ
  • 戻り値: <boolean> ハンドラが見つかった場合はtrue、そうでない場合はfalse

diagnostics_channel.subscribe(name, onMessage)でこのチャネルに登録されたメッセージハンドラを削除します。

import diagnostics_channel from 'node:diagnostics_channel';

function onMessage(message, name) {
  // Received data
}

diagnostics_channel.subscribe('my-channel', onMessage);

diagnostics_channel.unsubscribe('my-channel', onMessage);const diagnostics_channel = require('node:diagnostics_channel');

function onMessage(message, name) {
  // Received data
}

diagnostics_channel.subscribe('my-channel', onMessage);

diagnostics_channel.unsubscribe('my-channel', onMessage);
diagnostics_channel.tracingChannel(nameOrChannels)#

安定性: 1 - 試験段階

指定されたTracingChannelチャネルTracingChannelラッパーを作成します。名前が指定されている場合、対応するトレースチャネルはtracing:${name}:${eventType}という形式で作成されます。ここでeventTypeTracingChannelチャネルのタイプに対応します。

import diagnostics_channel from 'node:diagnostics_channel';

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

// or...

const channelsByCollection = diagnostics_channel.tracingChannel({
  start: diagnostics_channel.channel('tracing:my-channel:start'),
  end: diagnostics_channel.channel('tracing:my-channel:end'),
  asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'),
  asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'),
  error: diagnostics_channel.channel('tracing:my-channel:error'),
});const diagnostics_channel = require('node:diagnostics_channel');

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

// or...

const channelsByCollection = diagnostics_channel.tracingChannel({
  start: diagnostics_channel.channel('tracing:my-channel:start'),
  end: diagnostics_channel.channel('tracing:my-channel:end'),
  asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'),
  asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'),
  error: diagnostics_channel.channel('tracing:my-channel:error'),
});

クラス: `Channel`#

クラスChannelは、データパイプライン内の個々の名前付きチャネルを表します。サブスクライバの追跡と、サブスクライバがいる場合のメッセージの公開に使用されます。公開時のチャネルのルックアップを避けるために個別のオブジェクトとして存在し、非常に高速な公開速度を実現し、非常に最小限のコストで大量の使用を可能にします。チャネルはdiagnostics_channel.channel(name)で作成されます。new Channel(name)でチャネルを直接構築することはサポートされていません。

channel.hasSubscribers#
  • 戻り値: <boolean> アクティブなサブスクライバがいる場合true

このチャネルにアクティブなサブスクライバがいるかどうかを確認します。送信したいメッセージの準備にコストがかかる場合に便利です。

このAPIはオプションですが、非常にパフォーマンスに敏感なコードからメッセージを公開しようとする場合に役立ちます。

import diagnostics_channel from 'node:diagnostics_channel';

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

if (channel.hasSubscribers) {
  // There are subscribers, prepare and publish message
}const diagnostics_channel = require('node:diagnostics_channel');

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

if (channel.hasSubscribers) {
  // There are subscribers, prepare and publish message
}
channel.publish(message)#
  • message <any> チャネルサブスクライバに送信するメッセージ

チャネルのサブスクライバにメッセージを公開します。これにより、メッセージハンドラが同期的にトリガーされ、同じコンテキスト内で実行されます。

import diagnostics_channel from 'node:diagnostics_channel';

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

channel.publish({
  some: 'message',
});const diagnostics_channel = require('node:diagnostics_channel');

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

channel.publish({
  some: 'message',
});
channel.subscribe(onMessage)#

安定性: 0 - 非推奨: diagnostics_channel.subscribe(name, onMessage) を使用してください

  • onMessage <Function> チャネルメッセージを受信するハンドラ

このチャネルを購読するメッセージハンドラを登録します。このメッセージハンドラは、チャネルにメッセージが公開されるたびに同期的に実行されます。メッセージハンドラでスローされたエラーは、'uncaughtException' をトリガーします。

import diagnostics_channel from 'node:diagnostics_channel';

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

channel.subscribe((message, name) => {
  // Received data
});const diagnostics_channel = require('node:diagnostics_channel');

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

channel.subscribe((message, name) => {
  // Received data
});
channel.unsubscribe(onMessage)#

安定性: 0 - 非推奨: diagnostics_channel.unsubscribe(name, onMessage) を使用してください

  • onMessage <Function> 削除する前に登録されたハンドラ
  • 戻り値: <boolean> ハンドラが見つかった場合はtrue、そうでない場合はfalse

channel.subscribe(onMessage)でこのチャネルに登録されたメッセージハンドラを削除します。

import diagnostics_channel from 'node:diagnostics_channel';

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

function onMessage(message, name) {
  // Received data
}

channel.subscribe(onMessage);

channel.unsubscribe(onMessage);const diagnostics_channel = require('node:diagnostics_channel');

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

function onMessage(message, name) {
  // Received data
}

channel.subscribe(onMessage);

channel.unsubscribe(onMessage);
channel.bindStore(store[, transform])#

安定性: 1 - 試験段階

  • store <AsyncLocalStorage> コンテキストデータをバインドするストア
  • transform <Function> ストアコンテキストを設定する前にコンテキストデータを変換する関数

channel.runStores(context, ...)が呼び出されると、指定されたコンテキストデータはチャネルにバインドされているすべてのストアに適用されます。ストアが既にバインドされている場合、前のtransform関数は新しい関数で置き換えられます。指定されたコンテキストデータを直接コンテキストとして設定するには、transform関数を省略できます。

import diagnostics_channel from 'node:diagnostics_channel';
import { AsyncLocalStorage } from 'node:async_hooks';

const store = new AsyncLocalStorage();

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

channel.bindStore(store, (data) => {
  return { data };
});const diagnostics_channel = require('node:diagnostics_channel');
const { AsyncLocalStorage } = require('node:async_hooks');

const store = new AsyncLocalStorage();

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

channel.bindStore(store, (data) => {
  return { data };
});
channel.unbindStore(store)#

安定性: 1 - 試験段階

  • store <AsyncLocalStorage> チャネルからunbindするストア。
  • 戻り値: <boolean> ストアが見つかった場合はtrue、そうでない場合はfalse

channel.bindStore(store)でこのチャネルに登録されたメッセージハンドラを削除します。

import diagnostics_channel from 'node:diagnostics_channel';
import { AsyncLocalStorage } from 'node:async_hooks';

const store = new AsyncLocalStorage();

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

channel.bindStore(store);
channel.unbindStore(store);const diagnostics_channel = require('node:diagnostics_channel');
const { AsyncLocalStorage } = require('node:async_hooks');

const store = new AsyncLocalStorage();

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

channel.bindStore(store);
channel.unbindStore(store);
channel.runStores(context, fn[, thisArg[, ...args]])#

安定性: 1 - 試験段階

  • context <any> サブスクライバに送信し、ストアにバインドするメッセージ
  • fn <Function> 指定されたストレージコンテキスト内で実行するハンドラ
  • thisArg <any> 関数呼び出しに使用するレシーバ。
  • ...args <any> 関数に渡すオプションの引数。

指定された関数の期間、チャネルにバインドされているAsyncLocalStorageインスタンスに指定されたデータ適用し、そのデータがストアに適用されたスコープ内でチャネルにパブリッシュします。

channel.bindStore(store)にトランスフォーム関数が指定されている場合、メッセージデータがストアのコンテキスト値になる前に、それを変換するために適用されます。コンテキストのリンクが必要な場合は、トランスフォーム関数内で以前のストレージコンテキストにアクセスできます。

ストアに適用されたコンテキストは、指定された関数の実行中に開始された実行から続く非同期コードであればアクセスできますが、コンテキストの消失が発生する可能性のある状況もあります。

import diagnostics_channel from 'node:diagnostics_channel';
import { AsyncLocalStorage } from 'node:async_hooks';

const store = new AsyncLocalStorage();

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

channel.bindStore(store, (message) => {
  const parent = store.getStore();
  return new Span(message, parent);
});
channel.runStores({ some: 'message' }, () => {
  store.getStore(); // Span({ some: 'message' })
});const diagnostics_channel = require('node:diagnostics_channel');
const { AsyncLocalStorage } = require('node:async_hooks');

const store = new AsyncLocalStorage();

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

channel.bindStore(store, (message) => {
  const parent = store.getStore();
  return new Span(message, parent);
});
channel.runStores({ some: 'message' }, () => {
  store.getStore(); // Span({ some: 'message' })
});

クラス: TracingChannel#

安定性: 1 - 試験段階

クラスTracingChannelは、単一のトレース可能なアクションをまとめて表現するTracingChannelチャネルの集合です。アプリケーションフローのトレースのためのイベント生成のプロセスを形式化し、簡素化するために使用されます。diagnostics_channel.tracingChannel()を使用してTracingChannelを構築します。Channelと同様に、動的に作成するのではなく、ファイルの最上位レベルで単一のTracingChannelを作成して再利用することをお勧めします。

tracingChannel.subscribe(subscribers)#

安定性: 1 - 試験段階

対応するチャネルに一連の関数をサブスクライブするヘルパー。これは、各チャネルに対して個別にchannel.subscribe(onMessage)を呼び出すことと同じです。

import diagnostics_channel from 'node:diagnostics_channel';

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

channels.subscribe({
  start(message) {
    // Handle start message
  },
  end(message) {
    // Handle end message
  },
  asyncStart(message) {
    // Handle asyncStart message
  },
  asyncEnd(message) {
    // Handle asyncEnd message
  },
  error(message) {
    // Handle error message
  },
});const diagnostics_channel = require('node:diagnostics_channel');

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

channels.subscribe({
  start(message) {
    // Handle start message
  },
  end(message) {
    // Handle end message
  },
  asyncStart(message) {
    // Handle asyncStart message
  },
  asyncEnd(message) {
    // Handle asyncEnd message
  },
  error(message) {
    // Handle error message
  },
});
tracingChannel.unsubscribe(subscribers)#

安定性: 1 - 試験段階

対応するチャネルから一連の関数をアンサブスクライブするヘルパー。これは、各チャネルに対して個別にchannel.unsubscribe(onMessage)を呼び出すことと同じです。

import diagnostics_channel from 'node:diagnostics_channel';

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

channels.unsubscribe({
  start(message) {
    // Handle start message
  },
  end(message) {
    // Handle end message
  },
  asyncStart(message) {
    // Handle asyncStart message
  },
  asyncEnd(message) {
    // Handle asyncEnd message
  },
  error(message) {
    // Handle error message
  },
});const diagnostics_channel = require('node:diagnostics_channel');

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

channels.unsubscribe({
  start(message) {
    // Handle start message
  },
  end(message) {
    // Handle end message
  },
  asyncStart(message) {
    // Handle asyncStart message
  },
  asyncEnd(message) {
    // Handle asyncEnd message
  },
  error(message) {
    // Handle error message
  },
});
tracingChannel.traceSync(fn[, context[, thisArg[, ...args]]])#

安定性: 1 - 試験段階

  • fn <Function> トレースをラップする関数
  • context <Object> イベントを相互に関連付ける共有オブジェクト
  • thisArg <any> 関数呼び出しに使用するレシーバ
  • ...args <any> 関数に渡すオプションの引数
  • 戻り値: <any> 指定された関数の戻り値

同期関数の呼び出しをトレースします。これにより、実行の周囲に常にstartイベントendイベントが生成され、指定された関数がエラーをスローした場合にerrorイベントが生成される可能性があります。これは、startチャネルでchannel.runStores(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',
});
tracingChannel.tracePromise(fn[, context[, thisArg[, ...args]]])#

安定性: 1 - 試験段階

  • fn <Function> トレースをラップするPromiseを返す関数
  • context <Object> トレースイベントを相互に関連付ける共有オブジェクト
  • thisArg <any> 関数呼び出しに使用するレシーバ
  • ...args <any> 関数に渡すオプションの引数
  • 戻り値: <Promise> 指定された関数から返されるPromiseからチェーンされたもの

Promiseを返す関数の呼び出しをトレースします。これにより、関数の同期部分の周囲に常にstartイベントendイベントが生成され、Promiseの継続に到達するとasyncStartイベントasyncEndイベントが生成されます。指定された関数がエラーをスローするか、返されたPromiseが拒否された場合にも、errorイベントが生成される可能性があります。これは、startチャネルでchannel.runStores(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',
});
tracingChannel.traceCallback(fn, position, context, thisArg, ...args)#

安定性: 1 - 試験段階

  • fn <Function> トレースをラップするコールバックを使用する関数
  • position <number> 期待されるコールバックのゼロベースの引数位置(undefinedが渡された場合は最後の引数にデフォルト設定)
  • context <Object> トレースイベントを相互に関連付ける共有オブジェクト(undefinedが渡された場合は{}にデフォルト設定)
  • thisArg <any> 関数呼び出しに使用するレシーバ
  • ...args <any> 関数に渡す引数(コールバックを含める必要があります)
  • 戻り値: <any> 指定された関数の戻り値

コールバックを受け取る関数の呼び出しをトレースします。コールバックは、通常使用されるエラーを最初の引数として使用する規約に従うことが期待されます。これにより、関数の同期部分の周囲に常にstartイベントendイベントが生成され、コールバックの実行の周囲にasyncStartイベントasyncEndイベントが生成されます。指定された関数がスローされた場合、またはコールバックに渡された最初の引数が設定されている場合にも、errorイベントが生成される可能性があります。これは、startチャネルでchannel.runStores(context, ...)を使用して指定された関数を実行し、すべてのイベントでバインドされたストアが、このトレースコンテキストに一致するように設定されることを保証します。

import diagnostics_channel from 'node:diagnostics_channel';

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

channels.traceCallback((arg1, callback) => {
  // Do something
  callback(null, 'result');
}, 1, {
  some: 'thing',
}, thisArg, arg1, callback);const diagnostics_channel = require('node:diagnostics_channel');

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

channels.traceCallback((arg1, callback) => {
  // Do something
  callback(null, 'result');
}, {
  some: 'thing',
}, thisArg, arg1, callback);

コールバックもchannel.runStores(context, ...)を使用して実行されるため、場合によってはコンテキストの消失からの回復が可能になります。

import diagnostics_channel from 'node:diagnostics_channel';
import { AsyncLocalStorage } from 'node:async_hooks';

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

// The start channel sets the initial store data to something
// and stores that store data value on the trace context object
channels.start.bindStore(myStore, (data) => {
  const span = new Span(data);
  data.span = span;
  return span;
});

// Then asyncStart can restore from that data it stored previously
channels.asyncStart.bindStore(myStore, (data) => {
  return data.span;
});const diagnostics_channel = require('node:diagnostics_channel');
const { AsyncLocalStorage } = require('node:async_hooks');

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

// The start channel sets the initial store data to something
// and stores that store data value on the trace context object
channels.start.bindStore(myStore, (data) => {
  const span = new Span(data);
  data.span = span;
  return span;
});

// Then asyncStart can restore from that data it stored previously
channels.asyncStart.bindStore(myStore, (data) => {
  return data.span;
});

TracingChannelチャネル#

TracingChannelは、単一のトレース可能なアクションの実行ライフサイクル内の特定のポイントを表す複数のdiagnostics_channelsの集合です。動作は、startendasyncStartasyncEnderrorからなる5つのdiagnostics_channelsに分割されます。単一のトレース可能なアクションは、すべてのイベント間で同じイベントオブジェクトを共有します。これは、weakmapを通じて相関を管理するのに役立ちます。

これらのイベントオブジェクトは、タスクが「完了」すると、resultまたはerror値で拡張されます。同期タスクの場合、resultは戻り値になり、errorは関数からスローされたものになります。コールバックベースの非同期関数では、resultはコールバックの2番目の引数になり、errorendイベントで表示されるスローされたエラー、またはasyncStartまたはasyncEndイベントのいずれかの最初のコールバック引数のいずれかになります。

トレースチャネルは、次の命名パターンに従う必要があります。

  • tracing:module.class.method:startまたはtracing:module.function:start
  • tracing:module.class.method:endまたはtracing:module.function:end
  • tracing:module.class.method:asyncStartまたはtracing:module.function:asyncStart
  • tracing:module.class.method:asyncEndまたはtracing:module.function:asyncEnd
  • tracing:module.class.method:errorまたはtracing:module.function:error
start(event)#
  • 名前: tracing:${name}:start

startイベントは、関数が呼び出された時点を表します。この時点では、イベントデータに関数の引数や、関数の実行のまさに開始時に利用できるその他のデータが含まれている可能性があります。

end(event)#
  • 名前: tracing:${name}:end

endイベントは、関数呼び出しが値を返す時点を表します。非同期関数の場合、これは、関数自体が内部的にreturn文を実行したときではなく、返されたPromiseが実行されたときです。この時点で、トレースされた関数が同期していた場合、resultフィールドは関数の戻り値に設定されます。または、errorフィールドが存在して、スローされたエラーを表す場合があります。

トレース可能なアクションが複数のエラーを生成する可能性があるため、エラーを追跡するには、errorイベントを具体的にリッスンすることをお勧めします。たとえば、失敗する非同期タスクは、タスクの同期部分の前に内部的に開始されてから、エラーをスローする可能性があります。

asyncStart(event)#
  • 名前: tracing:${name}:asyncStart

asyncStartイベントは、トレース可能な関数のコールバックまたは継続に到達した時点を表します。この時点では、コールバック引数など、アクションの「結果」を表すものが利用できる場合があります。

コールバックベースの関数の場合、コールバックの最初の引数は、undefinedまたはnullでない場合、errorフィールドに割り当てられ、2番目の引数はresultフィールドに割り当てられます。

Promiseの場合、resolveパスの引数はresultに割り当てられ、rejectパスの引数はerrorに割り当てられます。

トレース可能なアクションが複数のエラーを生成する可能性があるため、エラーを追跡するには、errorイベントを具体的にリッスンすることをお勧めします。たとえば、失敗する非同期タスクは、タスクの同期部分の前に内部的に開始されてから、エラーをスローする可能性があります。

asyncEnd(event)#
  • 名前: tracing:${name}:asyncEnd

asyncEndイベントは、非同期関数のコールバックが返された時点を表します。asyncStartイベントの後でイベントデータが変更される可能性は低いですが、コールバックが完了した時点を確認するのに役立つ場合があります。

error(event)#
  • 名称: tracing:${name}:error

error イベントは、トレース可能な関数が同期的にまたは非同期的に生成したエラーを表します。トレースされた関数の同期部分でエラーがスローされると、エラーはイベントのerror フィールドに割り当てられ、error イベントがトリガーされます。コールバックまたはプロミス拒否を通じて非同期的にエラーを受け取ると、それもイベントのerror フィールドに割り当てられ、error イベントがトリガーされます。

単一のトレース可能な関数呼び出しで複数回エラーが発生する可能性があるため、このイベントを使用する際には考慮する必要があります。たとえば、内部で別の非同期タスクがトリガーされ失敗し、その後関数の同期部分がエラーをスローすると、同期エラーと非同期エラーの2つのerror イベントが発行されます。

組み込みチャネル#

安定性: 1 - 試験段階

diagnostics_channel API は現在安定版と見なされていますが、現在利用可能な組み込みチャネルは安定版ではありません。各チャネルは個別に安定版として宣言する必要があります。

HTTP#

http.client.request.start

クライアントがリクエストを開始したときに発行されます。

http.client.response.finish

クライアントがレスポンスを受信したときに発行されます。

http.server.request.start

サーバーがリクエストを受信したときに発行されます。

http.server.response.finish

サーバーがレスポンスを送信したときに発行されます。

NET#

net.client.socket

新しいTCPまたはパイプクライアントソケットが作成されたときに発行されます。

net.server.socket

新しいTCPまたはパイプ接続が受信されたときに発行されます。

UDP#

udp.socket

新しいUDPソケットが作成されたときに発行されます。

プロセス#

子プロセス

新しいプロセスが作成されたときに発行されます。

ワーカスレッド#

worker_threads

新しいスレッドが作成されたときに発行されます。