诊断通道#

稳定性:2 - 稳定

源代码: lib/diagnostics_channel.js

node:diagnostics_channel 模块提供了一个 API 来创建命名通道,以报告用于诊断目的的任意消息数据。

可以使用以下方式访问它

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

模块编写者希望报告诊断消息,将会创建一个或多个顶级通道来传递消息。 通道也可以在运行时获取,但不建议这样做,因为这样做会增加额外的开销。 为了方便起见,可以导出通道,但只要知道名称,就可以在任何地方获取它。

如果你希望你的模块生成诊断数据供其他人使用,建议你包含有关使用哪些命名通道以及消息数据形状的文档。 通道名称通常应包含模块名称,以避免与其他模块的数据发生冲突。

公共 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} 的形式创建相应的跟踪通道,其中 eventType 对应于 TracingChannel 通道的类型。

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> 是否有活动的订阅者

检查此通道是否存在活动的订阅者。 如果你要发送的消息准备起来可能很昂贵,这将很有帮助。

这个 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)#

注册一个消息处理函数以订阅此通道。 每当消息发布到通道时,将同步运行此消息处理函数。 消息处理函数中抛出的任何错误都将触发 '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 - 实验性的

当调用 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> 要从通道取消绑定的存储。
  • 返回:<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)#

帮助程序,用于将一组函数订阅到相应的通道。这与在每个通道上单独调用 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 的函数调用。这将始终在函数执行的同步部分生成 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 通道 是否有订阅者。 如果它们中的任何一个至少有一个订阅者,则返回 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_channels 的集合,这些通道表示单个可追踪操作的执行生命周期中的特定点。 该行为分为五个 diagnostics_channels,包括 startendasyncStartasyncEnderror。 单个可追踪操作将在所有事件之间共享相同的事件对象,这对于通过弱映射管理关联可能很有用。

当任务“完成”时,这些事件对象将被扩展为 resulterror 值。 对于同步任务,result 将是返回值,而 error 将是从函数抛出的任何内容。 对于基于回调的异步函数,result 将是回调的第二个参数,而 error 将是 end 事件中可见的抛出错误,或 asyncStartasyncEnd 事件中的第一个回调参数。

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

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

  • tracing:module.class.method:starttracing:module.function:start
  • tracing:module.class.method:endtracing:module.function:end
  • tracing:module.class.method:asyncStarttracing:module.function:asyncStart
  • tracing:module.class.method:asyncEndtracing:module.function:asyncEnd
  • tracing:module.class.method:errortracing:module.function:error
start(event)#
  • 名称: tracing:${name}:start

start 事件表示调用函数的时间点。 此时,事件数据可能包含函数参数或在函数执行开始时可用的任何其他内容。

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

end 事件表示函数调用返回一个值的时间点。对于异步函数,这是指 Promise 返回的时间点,而不是函数本身在内部发出返回语句的时间点。 在这个时间点,如果被追踪的函数是同步的,则 result 字段将被设置为函数的返回值。 另外,也可能存在 error 字段,表示任何抛出的错误。

建议专门监听 error 事件来跟踪错误,因为可追踪的操作可能产生多个错误。 例如,一个失败的异步任务可能在任务的同步部分抛出错误之前就在内部启动。

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

asyncStart 事件表示已到达可追踪函数的回调或延续。 此时,诸如回调参数之类的内容可能可用,或者任何其他表达操作“结果”的内容。

对于基于回调的函数,如果回调的第一个参数不是 undefinednull,则将其分配给 error 字段,并将第二个参数分配给 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 事件。

单个可追踪函数调用可能会多次产生错误,因此在消费此事件时应考虑这一点。 例如,如果另一个异步任务在内部被触发并失败,然后函数的同步部分抛出错误,则将发出两个 error 事件,一个用于同步错误,另一个用于异步错误。

内置通道#

稳定性:1 - 实验性的

虽然 diagnostics_channel API 现在被认为是稳定的,但当前可用的内置通道不是。 每个通道必须独立声明为稳定。

Console#

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#

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

当服务器发送响应时发出。

模块#

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#

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#

udp.socket

当创建新的 UDP 套接字时发出。

进程#

child_process

当创建新进程时发出。

execve

当调用 process.execve() 时发出。

Worker Thread#

worker_threads

当创建新线程时发出。