Diagnostics_channel is a new experimental module that provides an API to create named channels to report arbitrary message data for diagnostic purposes.
This module was originally introduced in Node.js V15.1.0 and was passed back to V14.17.0 for testing on a larger scale.
Through Diagnostics_Channel, Node.js core and module authors can publish contextual data about what they are doing at a particular time. For example, this might be the host name and query string of a mysql query. Just use dc.channel(name), create a named channel, and call channel.publish(data) to send data to any listeners on that channel.
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
});
this.doQuery(queryString, values, callback);
};
Copy the code
Channels are like a large global event emitter, but are split up into separate objects to ensure they perform at their best. If nothing is listening for that channel, the overhead of publishing should be as close to zero as possible. Consuming channel data is as simple as using channel.subscribe(listener) to run a function every time a message is published to the channel.
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
channel.subscribe(({ query, host }) => {
console.log(`mysql query to ${host}: ${query}`);
});
Copy the code
The captured data can be used to provide context for what the application is doing at a particular time. This can be used to add trace data, track network and file system activity, record queries, and many other things. It is also a useful data source for diagnostic tools to get a clearer picture of what the application is doing at a given data point.
Courtesy of Stephen Belangle #34895.
The new crypto.randomuuid () method now allows random RFC 4122 version 4 UUID strings to be generated.
const { randomUUID } = require('crypto');
console.log(randomUUID());
// 'aa7c91a1-f8fc-4339-b9db-f93fc7233429'
Copy the code
Contributed by James M Snell#36729.
rightAbortController
和AbortSignal
Experimental support of
Node.js 14.17.0 adds experimental partial support for AbortController and AbortSignal.
Both constructors can be enabled globally using the — experimental-abortController flag.
In addition, several Node.js apis have been updated to support AbortSignal for cancellation. Their built-in constructors are not mandatory. Any third party substitute that meets the specification should be compatible.
AbortSignal support is added to the following methods.
-
child_process.exec
-
child_process.execFile
-
child_process.fork
-
child_process.spawn
-
dgram.createSocket
-
events.on
-
events.once
-
fs.readFile
-
fs.watch
-
fs.writeFile
-
http.request
-
https.request
-
http2Session.request
-
SetImmediate promises variant and setTimeout
-
The document.
- Undo legacy URL deprecation and change the status to Legacy (James M Snell) #37784
- Add legacy status to stability index (James M Snell) #37784
- Update report stable state of API (Gireesh Punathil) #35654
-
Deps:
- V8: Post back various patches for Apple silicon support (Li Bohong) #38051
- Upgrade ICU to 68.1 (Michael Zasso) #36187
- Upgrade to Libuv 1.41.0 (Colin Ihrig)#37360
-
http:
- Increase the HTTP. ClientRequest. GetRawHeaderNames () (simov) # 37660
- Start and end of a request is reported by diagnostics_channel (Stephen Belanger) #34895
-
To use.
- Add getSystemErrorMap() inline (EladKeyshawn)#38101
For more, see Release Notes