Skip to content

Commit c31ccec

Browse files
sirrealzbjornson
authored andcommitted
Use entry.details.kind if exists fallback entry.kind
Node 16 moved the PerformancyEntry. See https://nodejs.org/docs/latest-v16.x/api/deprecations.html#deprecations_dep0152_extension_performanceentry_properties Remove `buffered` observe option This option has been removed in Node 16: https://nodejs.org/docs/latest-v16.x/api/perf_hooks.html#perf_hooks_performanceobserver_observe_options This was redundant in Node <16 because `false` was already the default: https://nodejs.org/docs/latest-v15.x/api/perf_hooks.html#perf_hooks_performanceobserver_observe_options > buffered <boolean> … Default: false. Remove buffering comment
1 parent 436a674 commit c31ccec

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
- Don't add event listener to `process` if cluster module is not used.
1515
- fix: set labels for default memory metrics on linux
16+
- fix: fix DEP0152 deprecation warning in Node.js v16+
1617

1718
### Added
1819

lib/metrics/gc.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ module.exports = (registry, config = {}) => {
4141

4242
const obs = new perf_hooks.PerformanceObserver(list => {
4343
const entry = list.getEntries()[0];
44+
// Node < 16 uses entry.kind
45+
// Node >= 16 uses entry.detail.kind
46+
// See: https://nodejs.org/docs/latest-v16.x/api/deprecations.html#deprecations_dep0152_extension_performanceentry_properties
47+
const kind = entry.detail ? kinds[entry.detail.kind] : kinds[entry.kind];
4448

4549
// Convert duration from milliseconds to seconds
46-
gcHistogram.observe(
47-
Object.assign({ kind: kinds[entry.kind] }, labels),
48-
entry.duration / 1000,
49-
);
50+
gcHistogram.observe(Object.assign({ kind }, labels), entry.duration / 1000);
5051
});
5152

52-
// We do not expect too many gc events per second, so we do not use buffering
53-
obs.observe({ entryTypes: ['gc'], buffered: false });
53+
obs.observe({ entryTypes: ['gc'] });
5454
};
5555

5656
module.exports.metricNames = [NODEJS_GC_DURATION_SECONDS];

0 commit comments

Comments
 (0)