診断チャネル#

安定性: 2 - Stable

ソースコード: 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)#
  • name <string> | <symbol> チャネル名
  • 戻り値: <boolean> アクティブなサブスクライバがいる場合は true

指定された名前のチャネルにアクティブなサブスクライバがいるかどうかを確認します。これは、送信したいメッセージの準備にコストがかかる場合に役立ちます。

この 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 - Experimental

指定された 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)#
  • 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)#
  • 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 - Experimental

  • 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 - Experimental

  • store <AsyncLocalStorage> チャネルからアンバインドするストア。
  • 戻り値: <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 - Experimental

  • 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 - Experimental

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

tracingChannel.subscribe(subscribers)#

対応するチャネルに関数のコレクションをサブスクライブするためのヘルパーです。これは、各チャネルで個別に 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)#

対応するチャネルから関数のコレクションをアンサブスクライブするためのヘルパーです。これは、各チャネルで個別に 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]]])#
  • 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]]])#
  • fn <Function> トレースでラップする Promise を返す関数
  • context <Object> トレースイベントを相関させるための共有オブジェクト
  • thisArg <any> 関数呼び出しに使用されるレシーバ
  • ...args <any> 関数に渡すオプションの引数
  • 戻り値: <Promise> 指定された関数が返す 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]]]])#
  • 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');
}, 1, {
  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.hasSubscribers#
  • 戻り値: <boolean> 個々のチャネルのいずれかにサブスクライバがいる場合は true、いない場合は false

これは TracingChannel インスタンスで利用できるヘルパーメソッドで、TracingChannel のチャネル のいずれかにサブスクライバがいるかどうかを確認します。いずれかに少なくとも1つのサブスクライバがいる場合は true が返され、そうでない場合は false が返されます。

import diagnostics_channel from 'node:diagnostics_channel';

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

if (channels.hasSubscribers) {
  // Do something
}const diagnostics_channel = require('node:diagnostics_channel');

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

if (channels.hasSubscribers) {
  // Do something
}

TracingChannel のチャネル#

TracingChannel は、単一のトレース可能なアクションの実行ライフサイクルにおける特定の時点を表す複数の diagnostics_channel のコレクションです。動作は startendasyncStartasyncEnderror の5つの diagnostics_channel に分割されます。単一のトレース可能なアクションは、すべてのイベント間で同じイベントオブジェクトを共有します。これは、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 イベントがトリガーされます。コールバックまたは Promise の拒否を介して非同期的にエラーが受信された場合も、イベントの error フィールドに割り当てられ、error イベントがトリガーされます。

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

組み込みチャネル#

コンソール#

安定性: 1 - Experimental

イベント: 'console.log'#

console.log() が呼び出されたときに発行されます。console.log() に渡された引数の配列を受け取ります。

イベント: 'console.info'#

console.info() が呼び出されたときに発行されます。console.info() に渡された引数の配列を受け取ります。

イベント: 'console.debug'#

console.debug() が呼び出されたときに発行されます。console.debug() に渡された引数の配列を受け取ります。

イベント: 'console.warn'#

console.warn() が呼び出されたときに発行されます。console.warn() に渡された引数の配列を受け取ります。

イベント: 'console.error'#

console.error() が呼び出されたときに発行されます。console.error() に渡された引数の配列を受け取ります。

HTTP#

安定性: 1 - Experimental

イベント: 'http.client.request.created'#

クライアントがリクエストオブジェクトを作成したときに発行されます。http.client.request.start とは異なり、このイベントはリクエストが送信される前に発行されます。

イベント: 'http.client.request.start'#

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

イベント: 'http.client.request.error'#

クライアントリクエスト中にエラーが発生したときに発行されます。

イベント: 'http.client.response.finish'#

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

イベント: 'http.server.request.start'#

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

イベント: 'http.server.response.created'#

サーバーがレスポンスを作成したときに発行されます。このイベントはレスポンスが送信される前に発行されます。

イベント: 'http.server.response.finish'#

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

HTTP/2#

安定性: 1 - Experimental

イベント: 'http2.client.stream.created'#

クライアント上でストリームが作成されたときに発行されます。

イベント: 'http2.client.stream.start'#

クライアント上でストリームが開始されたときに発行されます。

イベント: 'http2.client.stream.error'#

クライアント上でのストリーム処理中にエラーが発生したときに発行されます。

イベント: 'http2.client.stream.finish'#

クライアント上でストリームが受信されたときに発行されます。

イベント: 'http2.client.stream.close'#

クライアント上でストリームが閉じられたときに発行されます。ストリームを閉じる際に使用された HTTP/2 エラーコードは、stream.rstCode プロパティを使用して取得できます。

イベント: 'http2.server.stream.created'#

サーバー上でストリームが作成されたときに発行されます。

イベント: 'http2.server.stream.start'#

サーバー上でストリームが開始されたときに発行されます。

イベント: 'http2.server.stream.error'#

サーバー上でのストリーム処理中にエラーが発生したときに発行されます。

イベント: 'http2.server.stream.finish'#

サーバー上でストリームが送信されたときに発行されます。

イベント: 'http2.server.stream.close'#

サーバー上でストリームが閉じられたときに発行されます。ストリームを閉じる際に使用された HTTP/2 エラーコードは、stream.rstCode プロパティを使用して取得できます。

モジュール#

安定性: 1 - Experimental

イベント: 'module.require.start'#
  • event <Object> 以下のプロパティを含む
    • id require() に渡された引数。モジュール名。
    • parentFilename require(id) を試みたモジュールの名前。

require() が実行されたときに発行されます。start イベント を参照してください。

イベント: 'module.require.end'#
  • event <Object> 以下のプロパティを含む
    • id require() に渡された引数。モジュール名。
    • parentFilename require(id) を試みたモジュールの名前。

require() 呼び出しが返ったときに発行されます。end イベント を参照してください。

イベント: 'module.require.error'#
  • event <Object> 以下のプロパティを含む
    • id require() に渡された引数。モジュール名。
    • parentFilename require(id) を試みたモジュールの名前。
  • error <Error>

require() がエラーをスローしたときに発行されます。error イベント を参照してください。

イベント: 'module.import.asyncStart'#
  • event <Object> 以下のプロパティを含む
    • id import() に渡された引数。モジュール名。
    • parentURL import(id) を試みたモジュールの URL オブジェクト。

import() が呼び出されたときに発行されます。asyncStart イベント を参照してください。

イベント: 'module.import.asyncEnd'#
  • event <Object> 以下のプロパティを含む
    • id import() に渡された引数。モジュール名。
    • parentURL import(id) を試みたモジュールの URL オブジェクト。

import() が完了したときに発行されます。asyncEnd イベント を参照してください。

イベント: 'module.import.error'#
  • event <Object> 以下のプロパティを含む
    • id import() に渡された引数。モジュール名。
    • parentURL import(id) を試みたモジュールの URL オブジェクト。
  • error <Error>

import() がエラーをスローしたときに発行されます。error イベント を参照してください。

NET#

安定性: 1 - Experimental

イベント: 'net.client.socket'#

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

イベント: 'net.server.socket'#

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

イベント: 'tracing:net.server.listen:asyncStart'#

net.Server.listen() が呼び出され、ポートまたはパイプが実際にセットアップされる前に発行されます。

イベント: 'tracing:net.server.listen:asyncEnd'#

net.Server.listen() が完了し、サーバーが接続を受け入れる準備ができたときに発行されます。

イベント: 'tracing:net.server.listen:error'#

net.Server.listen() がエラーを返しているときに発行されます。

UDP#

安定性: 1 - Experimental

イベント: 'udp.socket'#

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

プロセス#

安定性: 1 - Experimental

イベント: 'child_process'#

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

イベント: 'execve'#

process.execve() が呼び出されたときに発行されます。

ワーカースレッド#

安定性: 1 - Experimental

イベント: 'worker_threads'#

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