Skip to content

Commit 8bf14b5

Browse files
committed
chore(instrumentation-runtime-node): fix event loop utilization collector
1 parent 184be5e commit 8bf14b5

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

plugins/node/instrumentation-runtime-node/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
"access": "public"
4040
},
4141
"dependencies": {
42-
"@opentelemetry/instrumentation": "^0.53.0"
42+
"@opentelemetry/instrumentation": "^0.53.0",
4343
},
4444
"devDependencies": {
4545
"@opentelemetry/api": "^1.3.0",
4646
"@opentelemetry/sdk-metrics": "^1.20.0",
4747
"@types/mocha": "^10.0.6",
48-
"@types/node": "^22.1.0",
48+
"@types/node": "^18.18.14",
4949
"mocha": "7.2.0",
5050
"nyc": "^15.1.0",
5151
"rimraf": "5.0.10",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Histogram} from "perf_hooks";
2+
3+
declare module 'node:perf_hooks' {
4+
interface IntervalHistogram extends Histogram {
5+
/**
6+
* Enables the update interval timer. Returns `true` if the timer was
7+
* started, `false` if it was already started.
8+
* @since v11.10.0
9+
*/
10+
enable(): boolean;
11+
12+
/**
13+
* Disables the update interval timer. Returns `true` if the timer was
14+
* stopped, `false` if it was already stopped.
15+
* @since v11.10.0
16+
*/
17+
disable(): boolean;
18+
19+
count: number;
20+
}
21+
}

plugins/node/instrumentation-runtime-node/src/metrics/eventLoopUtilizationCollector.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const { eventLoopUtilization: eventLoopUtilizationCollector } = performance;
2323
export const NODEJS_EVENT_LOOP_UTILIZATION = 'eventloop.utilization';
2424

2525
export class EventLoopUtilizationCollector extends BaseCollector {
26+
private _lastValue?: EventLoopUtilization;
27+
2628
constructor(
2729
config: RuntimeNodeInstrumentationConfig = {},
2830
namePrefix: string
@@ -42,16 +44,13 @@ export class EventLoopUtilizationCollector extends BaseCollector {
4244
.addCallback(async observableResult => {
4345
if (!this._config.enabled) return;
4446

45-
const elu = eventLoopUtilizationCollector(this.scrape());
47+
const elu = eventLoopUtilizationCollector(this._lastValue);
4648
observableResult.observe(elu.utilization);
49+
this._lastValue = elu;
4750
});
4851
}
4952

5053
protected internalDisable(): void {}
5154

5255
protected internalEnable(): void {}
53-
54-
private scrape(): EventLoopUtilization {
55-
return eventLoopUtilizationCollector();
56-
}
5756
}

0 commit comments

Comments
 (0)