Skip to content

Commit 2cd9093

Browse files
committed
chore(instrumentation-runtime-node): fetch loop lag format in convention
1 parent d7c5108 commit 2cd9093

File tree

2 files changed

+28
-116
lines changed

2 files changed

+28
-116
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const NODE_JS_VERSION_ATTRIBUTE = "nodejs.version"

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

Lines changed: 27 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { RuntimeNodeInstrumentationConfig } from '../types';
17-
import { Meter } from '@opentelemetry/api';
18-
import { IntervalHistogram } from 'node:perf_hooks';
19-
import { BaseCollector } from './baseCollector';
16+
import {RuntimeNodeInstrumentationConfig} from '../types';
17+
import {Meter} from '@opentelemetry/api';
2018
import * as perf_hooks from 'node:perf_hooks';
19+
import {IntervalHistogram} from 'node:perf_hooks';
20+
import {BaseCollector} from './baseCollector';
21+
import {NODE_JS_VERSION_ATTRIBUTE} from "../consts/attributes";
22+
23+
const NODEJS_EVENTLOOP_LAG = 'eventloop.lag';
24+
const NODEJS_EVENTLOOP_LAG_ATTRIBUTE_TYPE = 'nodejs.eventloop.lag.type';
2125

22-
const NODEJS_EVENTLOOP_LAG = 'event_loop.lag_seconds';
23-
const NODEJS_EVENTLOOP_LAG_MIN = 'event_loop.lag_min_seconds';
24-
const NODEJS_EVENTLOOP_LAG_MAX = 'event_loop.lag_max_seconds';
25-
const NODEJS_EVENTLOOP_LAG_MEAN = 'event_loop.lag_mean_seconds';
26-
const NODEJS_EVENTLOOP_LAG_STDDEV = 'event_loop.lag_stddev_seconds';
27-
const NODEJS_EVENTLOOP_LAG_P50 = 'event_loop.lag_p50_seconds';
28-
const NODEJS_EVENTLOOP_LAG_P90 = 'event_loop.lag_p90_seconds';
29-
const NODEJS_EVENTLOOP_LAG_P99 = 'event_loop.lag_p99_seconds';
30-
31-
export const metricNames = [
32-
{ name: NODEJS_EVENTLOOP_LAG, description: 'Lag of event loop in seconds.' },
33-
{
34-
name: NODEJS_EVENTLOOP_LAG_MIN,
35-
description: 'The minimum recorded event loop delay.',
36-
},
37-
{
38-
name: NODEJS_EVENTLOOP_LAG_MAX,
39-
description: 'The maximum recorded event loop delay.',
40-
},
41-
{
42-
name: NODEJS_EVENTLOOP_LAG_MEAN,
43-
description: 'The mean of the recorded event loop delays.',
44-
},
45-
{
46-
name: NODEJS_EVENTLOOP_LAG_STDDEV,
47-
description: 'The standard deviation of the recorded event loop delays.',
48-
},
49-
{
50-
name: NODEJS_EVENTLOOP_LAG_P50,
51-
description: 'The 50th percentile of the recorded event loop delays.',
52-
},
53-
{
54-
name: NODEJS_EVENTLOOP_LAG_P90,
55-
description: 'The 90th percentile of the recorded event loop delays.',
56-
},
57-
{
58-
name: NODEJS_EVENTLOOP_LAG_P99,
59-
description: 'The 99th percentile of the recorded event loop delays.',
60-
},
61-
];
6226

6327
export interface EventLoopLagInformation {
6428
min: number;
@@ -84,65 +48,14 @@ export class EventLoopLagCollector extends BaseCollector<EventLoopLagInformation
8448
}
8549

8650
updateMetricInstruments(meter: Meter): void {
87-
const lag = meter.createObservableGauge(
88-
`${this.namePrefix}.${metricNames[0].name}`,
89-
{
90-
description: metricNames[0].description,
91-
unit: '1',
92-
}
93-
);
94-
const lagMin = meter.createObservableGauge(
95-
`${this.namePrefix}.${metricNames[1].name}`,
96-
{
97-
description: metricNames[1].description,
98-
unit: '1',
99-
}
100-
);
101-
const lagMax = meter.createObservableGauge(
102-
`${this.namePrefix}.${metricNames[2].name}`,
103-
{
104-
description: metricNames[2].description,
105-
unit: '1',
106-
}
107-
);
108-
const lagMean = meter.createObservableGauge(
109-
`${this.namePrefix}.${metricNames[3].name}`,
110-
{
111-
description: metricNames[3].description,
112-
unit: '1',
113-
}
114-
);
115-
const lagStddev = meter.createObservableGauge(
116-
`${this.namePrefix}.${metricNames[4].name}`,
117-
{
118-
description: metricNames[4].description,
119-
unit: '1',
120-
}
121-
);
122-
const lagp50 = meter.createObservableGauge(
123-
`${this.namePrefix}.${metricNames[5].name}`,
124-
{
125-
description: metricNames[5].description,
126-
unit: '1',
127-
}
128-
);
129-
const lagp90 = meter.createObservableGauge(
130-
`${this.namePrefix}.${metricNames[6].name}`,
51+
meter.createObservableGauge(
52+
`${this.namePrefix}.${NODEJS_EVENTLOOP_LAG}`,
13153
{
132-
description: metricNames[6].description,
133-
unit: '1',
134-
}
135-
);
136-
const lagp99 = meter.createObservableGauge(
137-
`${this.namePrefix}.${metricNames[7].name}`,
138-
{
139-
description: metricNames[7].description,
140-
unit: '1',
141-
}
142-
);
143-
144-
meter.addBatchObservableCallback(
145-
async observableResult => {
54+
description: "Event loop lag.",
55+
unit: 's'
56+
},
57+
)
58+
.addCallback(async observableResult => {
14659
if (this._scrapeQueue.length === 0) return;
14760

14861
const data = this._scrapeQueue.shift();
@@ -155,19 +68,18 @@ export class EventLoopLagCollector extends BaseCollector<EventLoopLagInformation
15568
}, start);
15669
});
15770

158-
observableResult.observe(lag, lagResult);
159-
observableResult.observe(lagMin, data.min);
160-
observableResult.observe(lagMax, data.max);
161-
observableResult.observe(lagMean, data.mean);
162-
observableResult.observe(lagStddev, data.stddev);
163-
observableResult.observe(lagp50, data.p50);
164-
observableResult.observe(lagp90, data.p90);
165-
observableResult.observe(lagp99, data.p99);
71+
observableResult.observe(lagResult, {
72+
[NODE_JS_VERSION_ATTRIBUTE]: process.version
73+
});
16674

167-
this._histogram.reset();
168-
},
169-
[lag, lagMin, lagMax, lagMean, lagStddev, lagp50, lagp90, lagp99]
170-
);
75+
for(const [value, attributeType] of Object.keys(data).entries()) {
76+
observableResult.observe(value, {
77+
[NODEJS_EVENTLOOP_LAG_ATTRIBUTE_TYPE]: attributeType,
78+
[NODE_JS_VERSION_ATTRIBUTE]: process.version
79+
});
80+
}
81+
82+
});
17183
}
17284

17385
internalEnable(): void {
@@ -193,8 +105,7 @@ export class EventLoopLagCollector extends BaseCollector<EventLoopLagInformation
193105
private _reportEventloopLag(start: [number, number]): number {
194106
const delta = process.hrtime(start);
195107
const nanosec = delta[0] * 1e9 + delta[1];
196-
const seconds = nanosec / 1e9;
197-
return seconds;
108+
return nanosec / 1e9;
198109
}
199110

200111
private checkNan(value: number) {

0 commit comments

Comments
 (0)