diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d0a70c..2e247886 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Breaking ### Changed +- Enable `bun.js` by catching `NotImplemented` error thrown in `perf_hooks.monitorEventLoopDelay` ### Added diff --git a/lib/metrics/eventLoopLag.js b/lib/metrics/eventLoopLag.js index 45d5c33d..7acbbcfc 100644 --- a/lib/metrics/eventLoopLag.js +++ b/lib/metrics/eventLoopLag.js @@ -37,32 +37,35 @@ module.exports = (registry, config = {}) => { const labelNames = Object.keys(labels); const registers = registry ? [registry] : undefined; - let collect; - if (!perf_hooks || !perf_hooks.monitorEventLoopDelay) { - collect = () => { - const start = process.hrtime(); - setImmediate(reportEventloopLag, start, lag, labels); - }; - } else { - const histogram = perf_hooks.monitorEventLoopDelay({ - resolution: config.eventLoopMonitoringPrecision, - }); - histogram.enable(); + let collect = () => { + const start = process.hrtime(); + setImmediate(reportEventloopLag, start, lag, labels); + }; - collect = () => { - const start = process.hrtime(); - setImmediate(reportEventloopLag, start, lag, labels); + if (perf_hooks && perf_hooks.monitorEventLoopDelay) { + try { + const histogram = perf_hooks.monitorEventLoopDelay({ + resolution: config.eventLoopMonitoringPrecision, + }); + histogram.enable(); - lagMin.set(labels, histogram.min / 1e9); - lagMax.set(labels, histogram.max / 1e9); - lagMean.set(labels, histogram.mean / 1e9); - lagStddev.set(labels, histogram.stddev / 1e9); - lagP50.set(labels, histogram.percentile(50) / 1e9); - lagP90.set(labels, histogram.percentile(90) / 1e9); - lagP99.set(labels, histogram.percentile(99) / 1e9); + collect = () => { + const start = process.hrtime(); + setImmediate(reportEventloopLag, start, lag, labels); - histogram.reset(); - }; + lagMin.set(labels, histogram.min / 1e9); + lagMax.set(labels, histogram.max / 1e9); + lagMean.set(labels, histogram.mean / 1e9); + lagStddev.set(labels, histogram.stddev / 1e9); + lagP50.set(labels, histogram.percentile(50) / 1e9); + lagP90.set(labels, histogram.percentile(90) / 1e9); + lagP99.set(labels, histogram.percentile(99) / 1e9); + + histogram.reset(); + }; + } catch { + // bun has `perf_hooks.monitorEventLoopDelay` defined but throws "NotImplemented" when called + } } const lag = new Gauge({