Skip to content

Commit 7418c78

Browse files
committed
chore(instrumentation-runtime-node): synchronize with convention
1 parent ade0ab9 commit 7418c78

13 files changed

+82
-215
lines changed

plugins/node/instrumentation-runtime-node/src/consts/attributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
* limitations under the License.
1515
*/
1616
export const NODE_JS_VERSION_ATTRIBUTE = 'nodejsruntime.version';
17-
export const V8_HEAP_SIZE_STATE_ATTRIBUTE = 'heap.size.state';
17+
export const V8_HEAP_SIZE_NAME_ATTRIBUTE = 'heap.space.name';
1818
export const V8_HEAP_SIZE = 'heap.size';

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ export class RuntimeNodeInstrumentation extends InstrumentationBase {
4141
this._collectors = [
4242
new EventLoopUtilizationCollector(
4343
this._config,
44-
ConventionalNamePrefix.NodeJsRuntime
44+
ConventionalNamePrefix.NodeJs
4545
),
4646
new EventLoopDelayCollector(
4747
this._config,
48-
ConventionalNamePrefix.NodeJsRuntime
48+
ConventionalNamePrefix.NodeJs
4949
),
50-
new GCCollector(this._config, ConventionalNamePrefix.V8EnjineRuntime),
50+
new GCCollector(this._config, ConventionalNamePrefix.V8js),
5151
new HeapSizeAndUsedCollector(
5252
this._config,
53-
ConventionalNamePrefix.V8EnjineRuntime
53+
ConventionalNamePrefix.V8js
5454
),
5555
new HeapSpacesSizeAndUsedCollector(
5656
this._config,
57-
ConventionalNamePrefix.V8EnjineRuntime
57+
ConventionalNamePrefix.V8js
5858
),
5959
];
6060
if (this._config.enabled) {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,21 @@ import { MetricCollector } from '../types/metricCollector';
1717
import { Meter } from '@opentelemetry/api';
1818
import { clearInterval } from 'node:timers';
1919
import { RuntimeNodeInstrumentationConfig } from '../types';
20-
import { NODE_JS_VERSION_ATTRIBUTE } from '../consts/attributes';
2120

22-
type VersionAttribute = { [NODE_JS_VERSION_ATTRIBUTE]: string };
2321

2422
export abstract class BaseCollector<T> implements MetricCollector {
2523
protected _config: RuntimeNodeInstrumentationConfig = {};
2624

2725
protected namePrefix: string;
2826
private _interval: NodeJS.Timeout | undefined;
2927
protected _scrapeQueue: T[] = [];
30-
protected versionAttribute: VersionAttribute;
3128

3229
protected constructor(
3330
config: RuntimeNodeInstrumentationConfig = {},
3431
namePrefix: string
3532
) {
3633
this._config = config;
3734
this.namePrefix = namePrefix;
38-
this.versionAttribute = { [NODE_JS_VERSION_ATTRIBUTE]: process.version };
3935
}
4036

4137
public disable(): void {

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

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,40 @@ import {IntervalHistogram} from 'node:perf_hooks';
2020
import {BaseCollector} from './baseCollector';
2121

2222
enum NodeJsEventLoopDelay {
23-
delay = 'eventloop.delay',
2423
min = 'eventloop.delay.min',
2524
max = 'eventloop.delay.max',
2625
mean = 'eventloop.delay.mean',
2726
stddev = 'eventloop.delay.stddev',
2827
p50 = 'eventloop.delay.p50',
2928
p90 = 'eventloop.delay.p90',
30-
p99 = 'eventloop.delay.p99',
29+
p99 = 'eventloop.delay.p99'
3130
}
3231

3332
export const metricNames: Record<
3433
NodeJsEventLoopDelay,
3534
{ description: string }
3635
> = {
37-
[NodeJsEventLoopDelay.delay]: {
38-
description: 'Lag of event loop in seconds.',
39-
},
4036
[NodeJsEventLoopDelay.min]: {
41-
description: 'The minimum recorded event loop delay.',
37+
description: 'Event loop minimum delay.',
4238
},
4339
[NodeJsEventLoopDelay.max]: {
44-
description: 'The maximum recorded event loop delay.',
40+
description: 'Event loop maximum delay.',
4541
},
4642
[NodeJsEventLoopDelay.mean]: {
47-
description: 'The mean of the recorded event loop delays.',
43+
description: 'Event loop mean delay.',
4844
},
4945
[NodeJsEventLoopDelay.stddev]: {
50-
description: 'The standard deviation of the recorded event loop delays.',
46+
description: 'Event loop standard deviation delay.',
5147
},
5248
[NodeJsEventLoopDelay.p50]: {
53-
description: 'The 50th percentile of the recorded event loop delays.',
49+
description: 'Event loop 50 percentile delay.',
5450
},
5551
[NodeJsEventLoopDelay.p90]: {
56-
description: 'The 90th percentile of the recorded event loop delays.',
52+
description: 'Event loop 90 percentile delay.',
5753
},
5854
[NodeJsEventLoopDelay.p99]: {
59-
description: 'The 99th percentile of the recorded event loop delays.',
60-
},
55+
description: 'Event loop 99 percentile delay.',
56+
}
6157
};
6258

6359
export interface EventLoopLagInformation {
@@ -84,13 +80,6 @@ export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformati
8480
}
8581

8682
updateMetricInstruments(meter: Meter): void {
87-
const delay = meter.createObservableGauge(
88-
`${this.namePrefix}.${NodeJsEventLoopDelay.delay}`,
89-
{
90-
description: metricNames[NodeJsEventLoopDelay.delay].description,
91-
unit: 's',
92-
}
93-
);
9483
const delayMin = meter.createObservableGauge(
9584
`${this.namePrefix}.${NodeJsEventLoopDelay.min}`,
9685
{
@@ -148,30 +137,17 @@ export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformati
148137
const data = this._scrapeQueue.shift();
149138
if (data === undefined) return;
150139

151-
const startHrTime = process.hrtime();
152-
const delayResult = await new Promise<number>(res => {
153-
setImmediate((start: [number, number]) => {
154-
res(this._reportEventloopLag(start));
155-
}, startHrTime);
156-
});
157-
158-
observableResult.observe(delay, delayResult, this.versionAttribute);
159-
observableResult.observe(delayMin, data.min, this.versionAttribute);
160-
observableResult.observe(delayMax, data.max, this.versionAttribute);
161-
observableResult.observe(delayMean, data.mean, this.versionAttribute);
162-
observableResult.observe(
163-
delayStddev,
164-
data.stddev,
165-
this.versionAttribute
166-
);
167-
observableResult.observe(delayp50, data.p50, this.versionAttribute);
168-
observableResult.observe(delayp90, data.p90, this.versionAttribute);
169-
observableResult.observe(delayp99, data.p99, this.versionAttribute);
140+
observableResult.observe(delayMin, data.min);
141+
observableResult.observe(delayMax, data.max);
142+
observableResult.observe(delayMean, data.mean);
143+
observableResult.observe(delayStddev, data.stddev);
144+
observableResult.observe(delayp50, data.p50);
145+
observableResult.observe(delayp90, data.p90);
146+
observableResult.observe(delayp99, data.p99);
170147

171148
this._histogram.reset();
172149
},
173150
[
174-
delay,
175151
delayMin,
176152
delayMax,
177153
delayMean,
@@ -197,17 +173,12 @@ export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformati
197173
max: this.checkNan(this._histogram.max / 1e9),
198174
mean: this.checkNan(this._histogram.mean / 1e9),
199175
stddev: this.checkNan(this._histogram.stddev / 1e9),
200-
p50: this.checkNan(this._histogram.percentile(90) / 1e9),
176+
p50: this.checkNan(this._histogram.percentile(50) / 1e9),
201177
p90: this.checkNan(this._histogram.percentile(90) / 1e9),
202178
p99: this.checkNan(this._histogram.percentile(99) / 1e9),
203179
};
204180
}
205181

206-
private _reportEventloopLag(start: [number, number]): number {
207-
const delta = process.hrtime(start);
208-
const nanosec = delta[0] * 1e9 + delta[1];
209-
return nanosec / 1e9;
210-
}
211182

212183
private checkNan(value: number) {
213184
return isNaN(value) ? 0 : value;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class EventLoopUtilizationCollector extends BaseCollector<EventLoopUtiliz
4444
return;
4545
}
4646
const elu = eventLoopUtilizationCollector(this._scrapeQueue.shift());
47-
observableResult.observe(elu.utilization, this.versionAttribute);
47+
observableResult.observe(elu.utilization);
4848
});
4949
}
5050

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ export class GCCollector extends BaseCollector<null> {
4949
this._gcDurationByKindHistogram?.record(
5050
entry.duration / 1000,
5151
Object.assign(
52-
{ [`${this.namePrefix}.gc.type`]: kind },
53-
this.versionAttribute
52+
{ [`${this.namePrefix}.gc.type`]: kind }
5453
)
5554
);
5655
});

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { BaseCollector } from './baseCollector';
1919
import { HeapSizes } from '../types/heapSizes';
2020
import {
2121
V8_HEAP_SIZE,
22-
V8_HEAP_SIZE_STATE_ATTRIBUTE,
22+
V8_HEAP_SIZE_NAME_ATTRIBUTE,
2323
} from '../consts/attributes';
2424

2525
export class HeapSizeAndUsedCollector extends BaseCollector<NodeJS.MemoryUsage> {
@@ -42,14 +42,12 @@ export class HeapSizeAndUsedCollector extends BaseCollector<NodeJS.MemoryUsage>
4242
const data = this._scrapeQueue.shift();
4343
if (data === undefined) return;
4444
observableResult.observe(data.heapTotal, {
45-
[`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]:
45+
[`${this.namePrefix}.${V8_HEAP_SIZE_NAME_ATTRIBUTE}`]:
4646
HeapSizes.Total,
47-
...this.versionAttribute,
4847
});
4948
observableResult.observe(data.heapUsed, {
50-
[`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]:
49+
[`${this.namePrefix}.${V8_HEAP_SIZE_NAME_ATTRIBUTE}`]:
5150
HeapSizes.Used,
52-
...this.versionAttribute,
5351
});
5452
});
5553
}

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@ import { Meter } from '@opentelemetry/api';
1818
import { BaseCollector } from './baseCollector';
1919
import * as v8 from 'node:v8';
2020
import { HeapSpaceInfo } from 'v8';
21-
import { V8_HEAP_SIZE_STATE_ATTRIBUTE } from '../consts/attributes';
21+
import { V8_HEAP_SIZE_NAME_ATTRIBUTE } from '../consts/attributes';
2222

2323
export enum V8HeapSpaceMetrics {
24-
spaceSize = 'heap.space_size',
25-
used = 'heap.space_used_size',
26-
available = 'heap.space_available_size',
27-
physical = 'heap.physical_space_size',
24+
heapLimit = 'memory.heap.limit',
25+
used = 'memory.heap.used',
26+
available = 'memory.heap.space.available_size',
27+
physical = 'memory.heap.space.physical_size',
2828
}
2929

3030
export const metricNames: Record<V8HeapSpaceMetrics, { description: string }> =
3131
{
32-
[V8HeapSpaceMetrics.spaceSize]: {
33-
description: 'Process heap space size total from Node.js in bytes.',
32+
[V8HeapSpaceMetrics.heapLimit]: {
33+
description: 'Total heap memory size pre-allocated.',
3434
},
3535
[V8HeapSpaceMetrics.used]: {
36-
description: 'Process heap space size used from Node.js in bytes.',
36+
description: 'Heap Memory size allocated.',
3737
},
3838
[V8HeapSpaceMetrics.available]: {
39-
description: 'Process heap space size available from Node.js in bytes.',
39+
description: 'Heap space available size.',
4040
},
4141
[V8HeapSpaceMetrics.physical]: {
42-
description: 'Process heap space size available from Node.js in bytes.',
42+
description: 'Committed size of a heap space.',
4343
},
4444
};
4545

@@ -54,35 +54,35 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector<
5454
}
5555

5656
updateMetricInstruments(meter: Meter): void {
57-
const heapSpaceSize = meter.createObservableGauge(
58-
`${this.namePrefix}.${V8HeapSpaceMetrics.spaceSize}`,
57+
const heapLimit = meter.createObservableGauge(
58+
`${this.namePrefix}.${V8HeapSpaceMetrics.heapLimit}`,
5959
{
60-
description: metricNames[V8HeapSpaceMetrics.spaceSize].description,
61-
unit: 'bytes',
60+
description: metricNames[V8HeapSpaceMetrics.heapLimit].description,
61+
unit: 'By',
6262
}
6363
);
6464
const heapSpaceUsed = meter.createObservableGauge(
6565
`${this.namePrefix}.${V8HeapSpaceMetrics.used}`,
6666
{
6767
description: metricNames[V8HeapSpaceMetrics.used].description,
68-
unit: 'bytes',
68+
unit: 'By',
6969
}
7070
);
7171
const heapSpaceAvailable = meter.createObservableGauge(
7272
`${this.namePrefix}.${V8HeapSpaceMetrics.available}`,
7373
{
7474
description: metricNames[V8HeapSpaceMetrics.available].description,
75-
unit: 'bytes',
75+
unit: 'By',
7676
}
7777
);
7878
const heapSpacePhysical = meter.createObservableGauge(
7979
`${this.namePrefix}.${V8HeapSpaceMetrics.physical}`,
8080
{
8181
description: metricNames[V8HeapSpaceMetrics.physical].description,
82-
unit: 'bytes',
82+
unit: 'By',
8383
}
8484
);
85-
const heapSpaceNameAttributeName = `${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`;
85+
const heapSpaceNameAttributeName = `${this.namePrefix}.${V8_HEAP_SIZE_NAME_ATTRIBUTE}`;
8686

8787
meter.addBatchObservableCallback(
8888
observableResult => {
@@ -93,7 +93,7 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector<
9393
for (const space of data) {
9494
const spaceName = space.space_name;
9595

96-
observableResult.observe(heapSpaceSize, space.space_size, {
96+
observableResult.observe(heapLimit, space.space_size, {
9797
[heapSpaceNameAttributeName]: spaceName,
9898
});
9999

@@ -118,7 +118,7 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector<
118118
);
119119
}
120120
},
121-
[heapSpaceSize, heapSpaceUsed, heapSpaceAvailable, heapSpacePhysical]
121+
[heapLimit, heapSpaceUsed, heapSpaceAvailable, heapSpacePhysical]
122122
);
123123
}
124124

plugins/node/instrumentation-runtime-node/src/types/ConventionalNamePrefix.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
* limitations under the License.
1515
*/
1616
export enum ConventionalNamePrefix {
17-
NodeJsRuntime = 'nodejsruntime',
18-
V8EnjineRuntime = 'v8jsengineruntime',
17+
NodeJs = 'nodejs',
18+
V8js = 'v8js',
1919
}

0 commit comments

Comments
 (0)