GIF89; GIF89; %PDF- %PDF- Mr.X
  
  __  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.129: ~ $
# Diagnostics Channel

<!-- YAML
added:
  - v15.1.0
  - v14.17.0
changes:
  - version:
      - v19.2.0
      - v18.13.0
    pr-url: https://github.com/nodejs/node/pull/45290
    description: diagnostics_channel is now Stable.
-->

<!--introduced_in=v15.1.0-->

> Stability: 2 - Stable

<!-- source_link=lib/diagnostics_channel.js -->

The `node:diagnostics_channel` module provides an API to create named channels
to report arbitrary message data for diagnostics purposes.

It can be accessed using:

```mjs
import diagnostics_channel from 'node:diagnostics_channel';
```

```cjs
const diagnostics_channel = require('node:diagnostics_channel');
```

It is intended that a module writer wanting to report diagnostics messages
will create one or many top-level channels to report messages through.
Channels may also be acquired at runtime but it is not encouraged
due to the additional overhead of doing so. Channels may be exported for
convenience, but as long as the name is known it can be acquired anywhere.

If you intend for your module to produce diagnostics data for others to
consume it is recommended that you include documentation of what named
channels are used along with the shape of the message data. Channel names
should generally include the module name to avoid collisions with data from
other modules.

## Public API

### Overview

Following is a simple overview of the public API.

```mjs
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);
```

```cjs
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)`

<!-- YAML
added:
 - v15.1.0
 - v14.17.0
-->

* `name` {string|symbol} The channel name
* Returns: {boolean} If there are active subscribers

Check if there are active subscribers to the named channel. This is helpful if
the message you want to send might be expensive to prepare.

This API is optional but helpful when trying to publish messages from very
performance-sensitive code.

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

```cjs
const diagnostics_channel = require('node:diagnostics_channel');

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

#### `diagnostics_channel.channel(name)`

<!-- YAML
added:
 - v15.1.0
 - v14.17.0
-->

* `name` {string|symbol} The channel name
* Returns: {Channel} The named channel object

This is the primary entry-point for anyone wanting to publish to a named
channel. It produces a channel object which is optimized to reduce overhead at
publish time as much as possible.

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

```cjs
const diagnostics_channel = require('node:diagnostics_channel');

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

#### `diagnostics_channel.subscribe(name, onMessage)`

<!-- YAML
added:
 - v18.7.0
 - v16.17.0
-->

* `name` {string|symbol} The channel name
* `onMessage` {Function} The handler to receive channel messages
  * `message` {any} The message data
  * `name` {string|symbol} The name of the channel

Register a message handler to subscribe to this channel. This message handler
will be run synchronously whenever a message is published to the channel. Any
errors thrown in the message handler will trigger an [`'uncaughtException'`][].

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

```cjs
const diagnostics_channel = require('node:diagnostics_channel');

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

#### `diagnostics_channel.unsubscribe(name, onMessage)`

<!-- YAML
added:
 - v18.7.0
 - v16.17.0
-->

* `name` {string|symbol} The channel name
* `onMessage` {Function} The previous subscribed handler to remove
* Returns: {boolean} `true` if the handler was found, `false` otherwise.

Remove a message handler previously registered to this channel with
[`diagnostics_channel.subscribe(name, onMessage)`][].

```mjs
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);
```

```cjs
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)`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

> Stability: 1 - Experimental

* `nameOrChannels` {string|TracingChannel} Channel name or
  object containing all the [TracingChannel Channels][]
* Returns: {TracingChannel} Collection of channels to trace with

Creates a [`TracingChannel`][] wrapper for the given
[TracingChannel Channels][]. If a name is given, the corresponding tracing
channels will be created in the form of `tracing:${name}:${eventType}` where
`eventType` corresponds to the types of [TracingChannel Channels][].

```mjs
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'),
});
```

```cjs
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'),
});
```

### Class: `Channel`

<!-- YAML
added:
 - v15.1.0
 - v14.17.0
-->

The class `Channel` represents an individual named channel within the data
pipeline. It is used to track subscribers and to publish messages when there
are subscribers present. It exists as a separate object to avoid channel
lookups at publish time, enabling very fast publish speeds and allowing
for heavy use while incurring very minimal cost. Channels are created with
[`diagnostics_channel.channel(name)`][], constructing a channel directly
with `new Channel(name)` is not supported.

#### `channel.hasSubscribers`

<!-- YAML
added:
 - v15.1.0
 - v14.17.0
-->

* Returns: {boolean} If there are active subscribers

Check if there are active subscribers to this channel. This is helpful if
the message you want to send might be expensive to prepare.

This API is optional but helpful when trying to publish messages from very
performance-sensitive code.

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

if (channel.hasSubscribers) {
  // There are subscribers, prepare and publish message
}
```

```cjs
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)`

<!-- YAML
added:
 - v15.1.0
 - v14.17.0
-->

* `message` {any} The message to send to the channel subscribers

Publish a message to any subscribers to the channel. This will trigger
message handlers synchronously so they will execute within the same context.

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

channel.publish({
  some: 'message',
});
```

```cjs
const diagnostics_channel = require('node:diagnostics_channel');

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

channel.publish({
  some: 'message',
});
```

#### `channel.subscribe(onMessage)`

<!-- YAML
added:
 - v15.1.0
 - v14.17.0
changes:
  - version: v22.20.0
    pr-url: https://github.com/nodejs/node/pull/59758
    description: Deprecation revoked.
  - version:
    - v18.7.0
    - v16.17.0
    pr-url: https://github.com/nodejs/node/pull/44943
    description: Documentation-only deprecation.
-->

* `onMessage` {Function} The handler to receive channel messages
  * `message` {any} The message data
  * `name` {string|symbol} The name of the channel

Register a message handler to subscribe to this channel. This message handler
will be run synchronously whenever a message is published to the channel. Any
errors thrown in the message handler will trigger an [`'uncaughtException'`][].

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

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

```cjs
const diagnostics_channel = require('node:diagnostics_channel');

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

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

#### `channel.unsubscribe(onMessage)`

<!-- YAML
added:
 - v15.1.0
 - v14.17.0
changes:
  - version: v22.20.0
    pr-url: https://github.com/nodejs/node/pull/59758
    description: Deprecation revoked.
  - version:
    - v18.7.0
    - v16.17.0
    pr-url: https://github.com/nodejs/node/pull/44943
    description: Documentation-only deprecation.
  - version:
    - v17.1.0
    - v16.14.0
    - v14.19.0
    pr-url: https://github.com/nodejs/node/pull/40433
    description: Added return value. Added to channels without subscribers.
-->

* `onMessage` {Function} The previous subscribed handler to remove
* Returns: {boolean} `true` if the handler was found, `false` otherwise.

Remove a message handler previously registered to this channel with
[`channel.subscribe(onMessage)`][].

```mjs
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);
```

```cjs
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])`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

> Stability: 1 - Experimental

* `store` {AsyncLocalStorage} The store to which to bind the context data
* `transform` {Function} Transform context data before setting the store context

When [`channel.runStores(context, ...)`][] is called, the given context data
will be applied to any store bound to the channel. If the store has already been
bound the previous `transform` function will be replaced with the new one.
The `transform` function may be omitted to set the given context data as the
context directly.

```mjs
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 };
});
```

```cjs
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)`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

> Stability: 1 - Experimental

* `store` {AsyncLocalStorage} The store to unbind from the channel.
* Returns: {boolean} `true` if the store was found, `false` otherwise.

Remove a message handler previously registered to this channel with
[`channel.bindStore(store)`][].

```mjs
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);
```

```cjs
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]])`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

> Stability: 1 - Experimental

* `context` {any} Message to send to subscribers and bind to stores
* `fn` {Function} Handler to run within the entered storage context
* `thisArg` {any} The receiver to be used for the function call.
* `...args` {any} Optional arguments to pass to the function.

Applies the given data to any AsyncLocalStorage instances bound to the channel
for the duration of the given function, then publishes to the channel within
the scope of that data is applied to the stores.

If a transform function was given to [`channel.bindStore(store)`][] it will be
applied to transform the message data before it becomes the context value for
the store. The prior storage context is accessible from within the transform
function in cases where context linking is required.

The context applied to the store should be accessible in any async code which
continues from execution which began during the given function, however
there are some situations in which [context loss][] may occur.

```mjs
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' })
});
```

```cjs
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' })
});
```

### Class: `TracingChannel`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

> Stability: 1 - Experimental

The class `TracingChannel` is a collection of [TracingChannel Channels][] which
together express a single traceable action. It is used to formalize and
simplify the process of producing events for tracing application flow.
[`diagnostics_channel.tracingChannel()`][] is used to construct a
`TracingChannel`. As with `Channel` it is recommended to create and reuse a
single `TracingChannel` at the top-level of the file rather than creating them
dynamically.

#### `tracingChannel.subscribe(subscribers)`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

* `subscribers` {Object} Set of [TracingChannel Channels][] subscribers
  * `start` {Function} The [`start` event][] subscriber
  * `end` {Function} The [`end` event][] subscriber
  * `asyncStart` {Function} The [`asyncStart` event][] subscriber
  * `asyncEnd` {Function} The [`asyncEnd` event][] subscriber
  * `error` {Function} The [`error` event][] subscriber

Helper to subscribe a collection of functions to the corresponding channels.
This is the same as calling [`channel.subscribe(onMessage)`][] on each channel
individually.

```mjs
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
  },
});
```

```cjs
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)`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

* `subscribers` {Object} Set of [TracingChannel Channels][] subscribers
  * `start` {Function} The [`start` event][] subscriber
  * `end` {Function} The [`end` event][] subscriber
  * `asyncStart` {Function} The [`asyncStart` event][] subscriber
  * `asyncEnd` {Function} The [`asyncEnd` event][] subscriber
  * `error` {Function} The [`error` event][] subscriber
* Returns: {boolean} `true` if all handlers were successfully unsubscribed,
  and `false` otherwise.

Helper to unsubscribe a collection of functions from the corresponding channels.
This is the same as calling [`channel.unsubscribe(onMessage)`][] on each channel
individually.

```mjs
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
  },
});
```

```cjs
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]]])`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

* `fn` {Function} Function to wrap a trace around
* `context` {Object} Shared object to correlate events through
* `thisArg` {any} The receiver to be used for the function call
* `...args` {any} Optional arguments to pass to the function
* Returns: {any} The return value of the given function

Trace a synchronous function call. This will always produce a [`start` event][]
and [`end` event][] around the execution and may produce an [`error` event][]
if the given function throws an error. This will run the given function using
[`channel.runStores(context, ...)`][] on the `start` channel which ensures all
events should have any bound stores set to match this trace context.

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

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

channels.traceSync(() => {
  // Do something
}, {
  some: 'thing',
});
```

```cjs
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]]])`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

* `fn` {Function} Promise-returning function to wrap a trace around
* `context` {Object} Shared object to correlate trace events through
* `thisArg` {any} The receiver to be used for the function call
* `...args` {any} Optional arguments to pass to the function
* Returns: {Promise} Chained from promise returned by the given function

Trace a promise-returning function call. This will always produce a
[`start` event][] and [`end` event][] around the synchronous portion of the
function execution, and will produce an [`asyncStart` event][] and
[`asyncEnd` event][] when a promise continuation is reached. It may also
produce an [`error` event][] if the given function throws an error or the
returned promise rejects. This will run the given function using
[`channel.runStores(context, ...)`][] on the `start` channel which ensures all
events should have any bound stores set to match this trace context.

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

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

channels.tracePromise(async () => {
  // Do something
}, {
  some: 'thing',
});
```

```cjs
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]]]])`

<!-- YAML
added:
 - v19.9.0
 - v18.19.0
-->

* `fn` {Function} callback using function to wrap a trace around
* `position` {number} Zero-indexed argument position of expected callback
  (defaults to last argument if `undefined` is passed)
* `context` {Object} Shared object to correlate trace events through (defaults
  to `{}` if `undefined` is passed)
* `thisArg` {any} The receiver to be used for the function call
* `...args` {any} arguments to pass to the function (must include the callback)
* Returns: {any} The return value of the given function

Trace a callback-receiving function call. The callback is expected to follow
the error as first arg convention typically used. This will always produce a
[`start` event][] and [`end` event][] around the synchronous portion of the
function execution, and will produce a [`asyncStart` event][] and
[`asyncEnd` event][] around the callback execution. It may also produce an
[`error` event][] if the given function throws or the first argument passed to
the callback is set. This will run the given function using
[`channel.runStores(context, ...)`][] on the `start` channel which ensures all
events should have any bound stores set to match this trace context.

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

```mjs
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);
```

```cjs
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);
```

The callback will also be run with [`channel.runStores(context, ...)`][] which
enables context loss recovery in some cases.

```mjs
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;
});
```

```cjs
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`

<!-- YAML
added:
 - v22.0.0
-->

* Returns: {boolean} `true` if any of the individual channels has a subscriber,
  `false` if not.

This is a helper method available on a [`TracingChannel`][] instance to check if
any of the [TracingChannel Channels][] have subscribers. A `true` is returned if
any of them have at least one subscriber, a `false` is returned otherwise.

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

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

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

```cjs
const diagnostics_channel = require('node:diagnostics_channel');

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

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

### TracingChannel Channels

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.

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:module.class.method:start` or `tracing:module.function:start`
* `tracing:module.class.method:end` or `tracing:module.function:end`
* `tracing:module.class.method:asyncStart` or `tracing:module.function:asyncStart`
* `tracing:module.class.method:asyncEnd` or `tracing:module.function:asyncEnd`
* `tracing:module.class.method:error` or `tracing:module.function:error`

#### `start(event)`

* Name: `tracing:${name}:start`

The `start` event represents the point at which a function is called. At this
point the event data may contain function arguments or anything else available
at the very start of the execution of the function.

#### `end(event)`

* Name: `tracing:${name}:end`

The `end` event represents the point at which a function call returns a value.
In the case of an async function this is when the promise returned not when the
function itself makes a return statement internally. At this point, if the
traced function was synchronous the `result` field will be set to the return
value of the function. Alternatively, the `error` field may be present to
represent any thrown errors.

It is recommended to listen specifically to the `error` event to track errors
as it may be possible for a traceable action to produce multiple errors. For
example, an async task which fails may be started internally before the sync
part of the task then throws an error.

#### `asyncStart(event)`

* Name: `tracing:${name}:asyncStart`

The `asyncStart` event represents the callback or continuation of a traceable
function being reached. At this point things like callback arguments may be
available, or anything else expressing the "result" of the action.

For callbacks-based functions, the first argument of the callback will be
assigned to the `error` field, if not `undefined` or `null`, and the second
argument will be assigned to the `result` field.

For promises, the argument to the `resolve` path will be assigned to `result`
or the argument to the `reject` path will be assign to `error`.

It is recommended to listen specifically to the `error` event to track errors
as it may be possible for a traceable action to produce multiple errors. For
example, an async task which fails may be started internally before the sync
part of the task then throws an error.

#### `asyncEnd(event)`

* Name: `tracing:${name}:asyncEnd`

The `asyncEnd` event represents the callback of an asynchronous function
returning. It's not likely event data will change after the `asyncStart` event,
however it may be useful to see the point where the callback completes.

#### `error(event)`

* Name: `tracing:${name}:error`

The `error` event represents any error produced by the traceable function
either synchronously or asynchronously. If an error is thrown in the
synchronous portion of the traced function the error will be assigned to the
`error` field of the event and the `error` event will be triggered. If an error
is received asynchronously through a callback or promise rejection it will also
be assigned to the `error` field of the event and trigger the `error` event.

It is possible for a single traceable function call to produce errors multiple
times so this should be considered when consuming this event. For example, if
another async task is triggered internally which fails and then the sync part
of the function then throws and error two `error` events will be emitted, one
for the sync error and one for the async error.

### Built-in Channels

#### Console

> Stability: 1 - Experimental

##### Event: `'console.log'`

* `args` {any\[]}

Emitted when `console.log()` is called. Receives and array of the arguments
passed to `console.log()`.

##### Event: `'console.info'`

* `args` {any\[]}

Emitted when `console.info()` is called. Receives and array of the arguments
passed to `console.info()`.

##### Event: `'console.debug'`

* `args` {any\[]}

Emitted when `console.debug()` is called. Receives and array of the arguments
passed to `console.debug()`.

##### Event: `'console.warn'`

* `args` {any\[]}

Emitted when `console.warn()` is called. Receives and array of the arguments
passed to `console.warn()`.

##### Event: `'console.error'`

* `args` {any\[]}

Emitted when `console.error()` is called. Receives and array of the arguments
passed to `console.error()`.

#### HTTP

> Stability: 1 - Experimental

##### Event: `'http.client.request.created'`

* `request` {http.ClientRequest}

Emitted when client creates a request object.
Unlike `http.client.request.start`, this event is emitted before the request has been sent.

##### Event: `'http.client.request.start'`

* `request` {http.ClientRequest}

Emitted when client starts a request.

##### Event: `'http.client.request.error'`

* `request` {http.ClientRequest}
* `error` {Error}

Emitted when an error occurs during a client request.

##### Event: `'http.client.response.finish'`

* `request` {http.ClientRequest}
* `response` {http.IncomingMessage}

Emitted when client receives a response.

##### Event: `'http.server.request.start'`

* `request` {http.IncomingMessage}
* `response` {http.ServerResponse}
* `socket` {net.Socket}
* `server` {http.Server}

Emitted when server receives a request.

##### Event: `'http.server.response.created'`

* `request` {http.IncomingMessage}
* `response` {http.ServerResponse}

Emitted when server creates a response.
The event is emitted before the response is sent.

##### Event: `'http.server.response.finish'`

* `request` {http.IncomingMessage}
* `response` {http.ServerResponse}
* `socket` {net.Socket}
* `server` {http.Server}

Emitted when server sends a response.

#### HTTP/2

> Stability: 1 - Experimental

##### Event: `'http2.client.stream.created'`

* `stream` {ClientHttp2Stream}
* `headers` {HTTP/2 Headers Object}

Emitted when a stream is created on the client.

##### Event: `'http2.client.stream.start'`

* `stream` {ClientHttp2Stream}
* `headers` {HTTP/2 Headers Object}

Emitted when a stream is started on the client.

##### Event: `'http2.client.stream.error'`

* `stream` {ClientHttp2Stream}
* `error` {Error}

Emitted when an error occurs during the processing of a stream on the client.

##### Event: `'http2.client.stream.finish'`

* `stream` {ClientHttp2Stream}
* `headers` {HTTP/2 Headers Object}
* `flags` {number}

Emitted when a stream is received on the client.

##### Event: `'http2.client.stream.close'`

* `stream` {ClientHttp2Stream}

Emitted when a stream is closed on the client. The HTTP/2 error code used when
closing the stream can be retrieved using the `stream.rstCode` property.

##### Event: `'http2.server.stream.created'`

* `stream` {ServerHttp2Stream}
* `headers` {HTTP/2 Headers Object}

Emitted when a stream is created on the server.

##### Event: `'http2.server.stream.start'`

* `stream` {ServerHttp2Stream}
* `headers` {HTTP/2 Headers Object}

Emitted when a stream is started on the server.

##### Event: `'http2.server.stream.error'`

* `stream` {ServerHttp2Stream}
* `error` {Error}

Emitted when an error occurs during the processing of a stream on the server.

##### Event: `'http2.server.stream.finish'`

* `stream` {ServerHttp2Stream}
* `headers` {HTTP/2 Headers Object}
* `flags` {number}

Emitted when a stream is sent on the server.

##### Event: `'http2.server.stream.close'`

* `stream` {ServerHttp2Stream}

Emitted when a stream is closed on the server. The HTTP/2 error code used when
closing the stream can be retrieved using the `stream.rstCode` property.

#### Modules

> Stability: 1 - Experimental

##### Event: `'module.require.start'`

* `event` {Object} containing the following properties
  * `id` Argument passed to `require()`. Module name.
  * `parentFilename` Name of the module that attempted to require(id).

Emitted when `require()` is executed. See [`start` event][].

##### Event: `'module.require.end'`

* `event` {Object} containing the following properties
  * `id` Argument passed to `require()`. Module name.
  * `parentFilename` Name of the module that attempted to require(id).

Emitted when a `require()` call returns. See [`end` event][].

##### Event: `'module.require.error'`

* `event` {Object} containing the following properties
  * `id` Argument passed to `require()`. Module name.
  * `parentFilename` Name of the module that attempted to require(id).
* `error` {Error}

Emitted when a `require()` throws an error. See [`error` event][].

##### Event: `'module.import.asyncStart'`

* `event` {Object} containing the following properties
  * `id` Argument passed to `import()`. Module name.
  * `parentURL` URL object of the module that attempted to import(id).

Emitted when `import()` is invoked. See [`asyncStart` event][].

##### Event: `'module.import.asyncEnd'`

* `event` {Object} containing the following properties
  * `id` Argument passed to `import()`. Module name.
  * `parentURL` URL object of the module that attempted to import(id).

Emitted when `import()` has completed. See [`asyncEnd` event][].

##### Event: `'module.import.error'`

* `event` {Object} containing the following properties
  * `id` Argument passed to `import()`. Module name.
  * `parentURL` URL object of the module that attempted to import(id).
* `error` {Error}

Emitted when a `import()` throws an error. See [`error` event][].

#### NET

> Stability: 1 - Experimental

##### Event: `'net.client.socket'`

* `socket` {net.Socket|tls.TLSSocket}

Emitted when a new TCP or pipe client socket connection is created.

##### Event: `'net.server.socket'`

* `socket` {net.Socket}

Emitted when a new TCP or pipe connection is received.

##### Event: `'tracing:net.server.listen:asyncStart'`

* `server` {net.Server}
* `options` {Object}

Emitted when [`net.Server.listen()`][] is invoked, before the port or pipe is actually setup.

##### Event: `'tracing:net.server.listen:asyncEnd'`

* `server` {net.Server}

Emitted when [`net.Server.listen()`][] has completed and thus the server is ready to accept connection.

##### Event: `'tracing:net.server.listen:error'`

* `server` {net.Server}
* `error` {Error}

Emitted when [`net.Server.listen()`][] is returning an error.

#### UDP

> Stability: 1 - Experimental

##### Event: `'udp.socket'`

* `socket` {dgram.Socket}

Emitted when a new UDP socket is created.

#### Process

> Stability: 1 - Experimental

<!-- YAML
added: v16.18.0
-->

##### Event: `'child_process'`

* `process` {ChildProcess}

Emitted when a new process is created.

##### Event: `'execve'`

* `execPath` {string}
* `args` {string\[]}
* `env` {string\[]}

Emitted when [`process.execve()`][] is invoked.

#### Worker Thread

> Stability: 1 - Experimental

<!-- YAML
added: v16.18.0
-->

##### Event: `'worker_threads'`

* `worker` {Worker}

Emitted when a new thread is created.

[TracingChannel Channels]: #tracingchannel-channels
[`'uncaughtException'`]: process.md#event-uncaughtexception
[`TracingChannel`]: #class-tracingchannel
[`asyncEnd` event]: #asyncendevent
[`asyncStart` event]: #asyncstartevent
[`channel.bindStore(store)`]: #channelbindstorestore-transform
[`channel.runStores(context, ...)`]: #channelrunstorescontext-fn-thisarg-args
[`channel.subscribe(onMessage)`]: #channelsubscribeonmessage
[`channel.unsubscribe(onMessage)`]: #channelunsubscribeonmessage
[`diagnostics_channel.channel(name)`]: #diagnostics_channelchannelname
[`diagnostics_channel.subscribe(name, onMessage)`]: #diagnostics_channelsubscribename-onmessage
[`diagnostics_channel.tracingChannel()`]: #diagnostics_channeltracingchannelnameorchannels
[`end` event]: #endevent
[`error` event]: #errorevent
[`net.Server.listen()`]: net.md#serverlisten
[`process.execve()`]: process.md#processexecvefile-args-env
[`start` event]: #startevent
[context loss]: async_context.md#troubleshooting-context-loss

Filemanager

Name Type Size Permission Actions
assets Folder 0755
addons.html File 107.46 KB 0644
addons.json.gz File 11.01 KB 0644
addons.md File 39.89 KB 0644
all.html File 8.67 MB 0644
all.json.gz File 1.01 MB 0644
assert.html File 215.02 KB 0644
assert.json.gz File 15.05 KB 0644
assert.md File 72.71 KB 0644
async_context.html File 85.71 KB 0644
async_context.json.gz File 7.18 KB 0644
async_context.md File 25.17 KB 0644
async_hooks.html File 88.88 KB 0644
async_hooks.json.gz File 9.82 KB 0644
async_hooks.md File 30.52 KB 0644
buffer.html File 484.41 KB 0644
buffer.json.gz File 29.12 KB 0644
buffer.md File 149.42 KB 0644
child_process.html File 214.18 KB 0644
child_process.json.gz File 21.81 KB 0644
child_process.md File 83.3 KB 0644
cli.html File 258.67 KB 0644
cli.json.gz File 39.13 KB 0644
cli.md File 113.19 KB 0644
cluster.html File 92.16 KB 0644
cluster.json.gz File 9.46 KB 0644
cluster.md File 28.89 KB 0644
console.html File 63.73 KB 0644
console.json.gz File 6.28 KB 0644
console.md File 17.38 KB 0644
corepack.html File 15.56 KB 0644
corepack.json File 866 B 0644
corepack.md File 401 B 0644
crypto.html File 526.52 KB 0644
crypto.json.gz File 46.5 KB 0644
crypto.md File 193.72 KB 0644
debugger.html File 30.54 KB 0644
debugger.json.gz File 3.42 KB 0644
debugger.md File 7.88 KB 0644
deprecations.html File 237.81 KB 0644
deprecations.json.gz File 28.63 KB 0644
deprecations.md File 117.72 KB 0644
dgram.html File 93.62 KB 0644
dgram.json.gz File 10.63 KB 0644
dgram.md File 32.28 KB 0644
diagnostics_channel.html File 130.69 KB 0644
diagnostics_channel.json.gz File 10.38 KB 0644
diagnostics_channel.md File 39.31 KB 0644
dns.html File 150.29 KB 0644
dns.json.gz File 16.91 KB 0644
dns.md File 59.01 KB 0644
documentation.html File 27.74 KB 0644
documentation.json.gz File 2.57 KB 0644
documentation.md File 5.68 KB 0644
domain.html File 49.94 KB 0644
domain.json.gz File 6.21 KB 0644
domain.md File 15.21 KB 0644
embedding.html File 27.42 KB 0644
embedding.json.gz File 3.03 KB 0644
embedding.md File 6.74 KB 0644
environment_variables.html File 24.29 KB 0644
environment_variables.json.gz File 2.58 KB 0644
environment_variables.md File 5.08 KB 0644
errors.html File 337.36 KB 0644
errors.json.gz File 47.68 KB 0644
errors.md File 112.09 KB 0644
esm.html File 93.22 KB 0644
esm.json.gz File 16 KB 0644
esm.md File 44.27 KB 0644
events.html File 236.33 KB 0644
events.json.gz File 17.91 KB 0644
events.md File 68.71 KB 0644
fs.html File 666.11 KB 0644
fs.json.gz File 71.32 KB 0644
fs.md File 263.58 KB 0644
globals.html File 98.26 KB 0644
globals.json.gz File 12.43 KB 0644
globals.md File 29.48 KB 0644
http.html File 330.81 KB 0644
http.json.gz File 40 KB 0644
http.md File 126.6 KB 0644
http2.html File 389.2 KB 0644
http2.json.gz File 42.34 KB 0644
http2.md File 152.2 KB 0644
https.html File 72.6 KB 0644
https.json.gz File 6.21 KB 0644
https.md File 21.04 KB 0644
index.html File 13.9 KB 0644
index.json File 54 B 0644
index.md File 2.06 KB 0644
inspector.html File 65.18 KB 0644
inspector.json.gz File 5.74 KB 0644
inspector.md File 17.75 KB 0644
intl.html File 34.48 KB 0644
intl.json.gz File 4.12 KB 0644
intl.md File 11.49 KB 0644
module.html File 171.06 KB 0644
module.json.gz File 21.59 KB 0644
module.md File 69.85 KB 0644
modules.html File 96.67 KB 0644
modules.json.gz File 14.83 KB 0644
modules.md File 40.53 KB 0644
n-api.html File 432.96 KB 0644
n-api.json.gz File 55.7 KB 0644
n-api.md File 235.86 KB 0644
net.html File 167.45 KB 0644
net.json.gz File 20.51 KB 0644
net.md File 60.3 KB 0644
os.html File 74.59 KB 0644
os.json.gz File 9.18 KB 0644
os.md File 36.29 KB 0644
packages.html File 89.9 KB 0644
packages.json.gz File 13.05 KB 0644
packages.md File 38.8 KB 0644
path.html File 57.7 KB 0644
path.json.gz File 5.43 KB 0644
path.md File 16.48 KB 0644
perf_hooks.html File 187.34 KB 0644
perf_hooks.json.gz File 13.83 KB 0644
perf_hooks.md File 59.15 KB 0644
permissions.html File 29.01 KB 0644
permissions.json.gz File 3.64 KB 0644
permissions.md File 8.35 KB 0644
process.html File 343.73 KB 0644
process.json.gz File 37.12 KB 0644
process.md File 128.36 KB 0644
punycode.html File 27.65 KB 0644
punycode.json.gz File 2 KB 0644
punycode.md File 4.19 KB 0644
querystring.html File 29.92 KB 0644
querystring.json.gz File 2.65 KB 0644
querystring.md File 5.55 KB 0644
readline.html File 115.99 KB 0644
readline.json.gz File 11.81 KB 0644
readline.md File 41.32 KB 0644
repl.html File 96.41 KB 0644
repl.json.gz File 11.56 KB 0644
repl.md File 31.55 KB 0644
report.html File 101.16 KB 0644
report.json.gz File 7.44 KB 0644
report.md File 23.41 KB 0644
single-executable-applications.html File 52.13 KB 0644
single-executable-applications.json.gz File 6.77 KB 0644
single-executable-applications.md File 18.27 KB 0644
sqlite.html File 92.73 KB 0644
sqlite.json.gz File 11 KB 0644
sqlite.md File 34.86 KB 0644
stream.html File 412.01 KB 0644
stream.json.gz File 53.26 KB 0644
stream.md File 152.09 KB 0644
string_decoder.html File 28.31 KB 0644
string_decoder.json.gz File 1.59 KB 0644
string_decoder.md File 3.57 KB 0644
synopsis.html File 20.35 KB 0644
synopsis.json File 2.96 KB 0644
synopsis.md File 2.11 KB 0644
test.html File 343.78 KB 0644
test.json.gz File 31.84 KB 0644
test.md File 122.47 KB 0644
timers.html File 62.4 KB 0644
timers.json.gz File 5.33 KB 0644
timers.md File 16.76 KB 0644
tls.html File 203.47 KB 0644
tls.json.gz File 35.24 KB 0644
tls.md File 98.58 KB 0644
tracing.html File 43.55 KB 0644
tracing.json.gz File 3.58 KB 0644
tracing.md File 10.58 KB 0644
tty.html File 40.73 KB 0644
tty.json.gz File 3.88 KB 0644
tty.md File 9.56 KB 0644
typescript.html File 29.27 KB 0644
typescript.json.gz File 3.38 KB 0644
typescript.md File 7.69 KB 0644
url.html File 161.29 KB 0644
url.json.gz File 16.67 KB 0644
url.md File 57.4 KB 0644
util.html File 351.85 KB 0644
util.json.gz File 30.22 KB 0644
util.md File 114.07 KB 0644
v8.html File 134.81 KB 0644
v8.json.gz File 14.51 KB 0644
v8.md File 43.79 KB 0644
vm.html File 188 KB 0644
vm.json.gz File 22.9 KB 0644
vm.md File 80.88 KB 0644
wasi.html File 32.28 KB 0644
wasi.json.gz File 3.49 KB 0644
wasi.md File 8.25 KB 0644
webcrypto.html File 161.61 KB 0644
webcrypto.json.gz File 10.2 KB 0644
webcrypto.md File 47.22 KB 0644
webstreams.html File 165.16 KB 0644
webstreams.json.gz File 10.95 KB 0644
webstreams.md File 41.21 KB 0644
worker_threads.html File 169.32 KB 0644
worker_threads.json.gz File 17.33 KB 0644
worker_threads.md File 59.46 KB 0644
zlib.html File 156.29 KB 0644
zlib.json.gz File 12.86 KB 0644
zlib.md File 49 KB 0644