From e8e81a723a5814d40a843408cd17a4101fad3c5d Mon Sep 17 00:00:00 2001 From: Daniel Li Date: Tue, 16 Jan 2024 11:46:33 +0000 Subject: [PATCH] fix(perf_hooks): don't export when disabled --- .../instrumentation-perf-hooks/src/instrumentation.ts | 1 + .../test/event_loop_utilization.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/plugins/node/instrumentation-perf-hooks/src/instrumentation.ts b/plugins/node/instrumentation-perf-hooks/src/instrumentation.ts index d545abfd67..a414fe4cd0 100644 --- a/plugins/node/instrumentation-perf-hooks/src/instrumentation.ts +++ b/plugins/node/instrumentation-perf-hooks/src/instrumentation.ts @@ -82,6 +82,7 @@ export class PerfHooksInstrumentation extends InstrumentationBase { } override disable() { + this._clearELU(); clearInterval(this._interval); this._interval = undefined; } diff --git a/plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts b/plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts index bc4a0a7e2f..c05dbf342b 100644 --- a/plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts +++ b/plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts @@ -86,4 +86,12 @@ describe('nodejs.performance.event_loop.utilization', () => { ); assert.strictEqual(metrics[0].descriptor.unit, '1'); }); + + it('should stop exporting metrics when disabled', async () => { + instrumentation.disable(); + await new Promise(resolve => setTimeout(resolve, EXPORT_INTERVAL)); + const resourceMetrics = metricExporter.getMetrics(); + const scopeMetrics = resourceMetrics[0].scopeMetrics; + assert.strictEqual(scopeMetrics.length, 0); + }); });