# node:diagnostics_channel

> How Elide supports Node's `diagnostics_channel` module: channels, tracing channels and stores, which built-in channels publish, and the `boundedChannel` addition.

`node:diagnostics_channel` provides `channel`, `subscribe`, `tracingChannel`, `bindStore` and `runStores` from
[Node's `diagnostics_channel`](https://nodejs.org/api/diagnostics_channel.html).

## Example

```js
// dc.mjs
import diagnostics from "node:diagnostics_channel";

const channel = diagnostics.channel("app:query");
diagnostics.subscribe("app:query", (message, name) => console.log(name, message.sql));
console.log("subscribers:", channel.hasSubscribers);
channel.publish({ sql: "select 1" });

const tracing = diagnostics.tracingChannel("app:job");
tracing.subscribe({
  start: () => console.log("start"),
  end: () => console.log("end"),
});
console.log(tracing.traceSync(() => 42));
```

`elide run dc.mjs` prints:

```text
subscribers: true
app:query select 1
start
end
42
```

## Differences from Node

- Elide adds `boundedChannel` and `BoundedChannel`.
- Channel stores follow the propagation rules in [`node:async_hooks`](https://elide.help/docs/api-node-async-hooks).
- `net.server.socket`, `tracing:module.import`, `http2.*`, `tls.*` and Web Locks channels are not published.

Built-in modules publish on these channels:

| Module | Publishes |
| --- | --- |
| `node:http` | client and server request channels |
| `node:net` | `net.client.socket`, `tracing:net.server.listen` |
| `node:dgram`, `node:child_process`, `node:worker_threads` | their Node channels |
| `require()` | `tracing:module.require` |

<!-- api-reference:start 0082489c31cb -->
## Reference

**Status:** Full · 42 of 67 suite tests pass (62.7%) · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `Channel` | class | Full | `name`, `hasSubscribers`, `publish()`, `subscribe()`, `unsubscribe()` |
| `channel()` | function | Full | Returns a Channel object for the given name, creating one if it does not exist |
| `hasSubscribers()` | function | Full | Returns whether the named channel has active subscribers |
| `subscribe()` | function | Full | Subscribe a handler to the named channel |
| `unsubscribe()` | function | Full | Unsubscribe a handler from the named channel |

**Tests:** [node-api `node:diagnostics-channel`](https://github.com/elide-dev/testsuite/blob/main/reports/1.6.0%2B6e718933f/4cbcae6c33a8/node-api/node-api.md): 42 pass, 25 fail, 0 error, 1 skipped. Failing: `test-diagnostics-channel-http2-client-stream-body-multiple-buffers-and-strings.js`, `test-diagnostics-channel-http2-client-stream-body-multiple-buffers.js`, `test-diagnostics-channel-http2-client-stream-body-no-chunks.js`, `test-diagnostics-channel-http2-client-stream-body-single-buffer.js`, `test-diagnostics-channel-http2-client-stream-body-single-string.js`, `test-diagnostics-channel-http2-client-stream-close-error.js`, `test-diagnostics-channel-http2-client-stream-close.js`, `test-diagnostics-channel-http2-client-stream-created.js`, and 17 more.
<!-- api-reference:end -->
