Skip to content

Commit

Permalink
Use entry.details.kind if exists fallback entry.kind
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sirreal authored and zbjornson committed Jul 31, 2021
1 parent 436a674 commit c31ccec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

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

### Added

Expand Down
12 changes: 6 additions & 6 deletions lib/metrics/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ module.exports = (registry, config = {}) => {

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

// Convert duration from milliseconds to seconds
gcHistogram.observe(
Object.assign({ kind: kinds[entry.kind] }, labels),
entry.duration / 1000,
);
gcHistogram.observe(Object.assign({ kind }, labels), entry.duration / 1000);
});

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

module.exports.metricNames = [NODEJS_GC_DURATION_SECONDS];

0 comments on commit c31ccec

Please sign in to comment.