Skip to content

Commit 8294c49

Browse files
committed
lib: add node:metrics module
This takes ideas from various ecosystem metrics modules along with some ideas from the Swift metrics provider. The idea being to provide a generic metrics interface which publishes diagnostics_channel events and allowing consumers to listen to those events and either report them directly or aggregate them in some way.
1 parent eaebfab commit 8294c49

16 files changed

Lines changed: 2388 additions & 0 deletions

doc/api/diagnostics_channel.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,35 @@ if (diagnostics_channel.hasSubscribers('my-channel')) {
132132
}
133133
```
134134

135+
#### `diagnostics_channel.hasChannel(name)`
136+
137+
<!-- YAML
138+
added: REPLACEME
139+
-->
140+
141+
* `name` {string|symbol} The channel name
142+
143+
* Returns: {boolean} If the channel exists
144+
145+
Check if a channel with the given name exists. This is useful to check if a
146+
channel has been created to add additional logic if it's the first time.
147+
148+
```mjs
149+
import diagnostics_channel from 'node:diagnostics_channel';
150+
151+
if (!diagnostics_channel.hasChannel('my-channel')) {
152+
// Channel does not exist yet, do additional setup
153+
}
154+
```
155+
156+
```cjs
157+
const diagnostics_channel = require('node:diagnostics_channel');
158+
159+
if (!diagnostics_channel.hasChannel('my-channel')) {
160+
// Channel does not exist yet, do additional setup
161+
}
162+
```
163+
135164
#### `diagnostics_channel.channel(name)`
136165

137166
<!-- YAML

doc/api/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* [HTTPS](https.md)
3737
* [Inspector](inspector.md)
3838
* [Internationalization](intl.md)
39+
* [Metrics](metrics.md)
3940
* [Modules: CommonJS modules](modules.md)
4041
* [Modules: ECMAScript modules](esm.md)
4142
* [Modules: `node:module` API](module.md)

0 commit comments

Comments
 (0)