Skip to content

Commit 6b5fc8b

Browse files
committed
chore(instrumentation-runtime-node): fix attributes names
1 parent 310a2b2 commit 6b5fc8b

File tree

11 files changed

+46
-65
lines changed

11 files changed

+46
-65
lines changed

plugins/node/instrumentation-runtime-node/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ nodejs_performance_event_loop_utilization 0.010140079547955264
6161
`RuntimeNodeInstrumentation`'s constructor accepts the following options:
6262
6363
| name | type | unit | default | description |
64-
|---|---|---|---|---|
65-
| [`monitoringPrecision`](./src/types.ts#L25) | `int` | millisecond | `5000` | The approximate number of milliseconds for which to calculate event loop utilization averages. A larger value will result in more accurate averages at the expense of less granular data. Should be set to below the scrape interval of your metrics collector to avoid duplicated data points. |
64+
|---|---|---|---------|---|
65+
| [`monitoringPrecision`](./src/types.ts#L25) | `int` | millisecond | `10` | The approximate number of milliseconds for which to calculate event loop utilization averages. A larger value will result in more accurate averages at the expense of less granular data. Should be set to below the scrape interval of your metrics collector to avoid duplicated data points. |
6666
6767
## Useful links
6868

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
export const V8_HEAP_SIZE_NAME_ATTRIBUTE = 'heap.space.name';
16+
export const ATTR_V8JS_HEAP_SPACE_NAME = 'heap.space.name';

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as perf_hooks from 'node:perf_hooks';
1919
import { IntervalHistogram } from 'node:perf_hooks';
2020
import { BaseCollector } from './baseCollector';
2121

22-
enum NodeJsEventLoopDelay {
22+
enum NodeJsEventLoopDelayAttributes {
2323
min = 'eventloop.delay.min',
2424
max = 'eventloop.delay.max',
2525
mean = 'eventloop.delay.mean',
@@ -30,28 +30,28 @@ enum NodeJsEventLoopDelay {
3030
}
3131

3232
export const metricNames: Record<
33-
NodeJsEventLoopDelay,
33+
NodeJsEventLoopDelayAttributes,
3434
{ description: string }
3535
> = {
36-
[NodeJsEventLoopDelay.min]: {
36+
[NodeJsEventLoopDelayAttributes.min]: {
3737
description: 'Event loop minimum delay.',
3838
},
39-
[NodeJsEventLoopDelay.max]: {
39+
[NodeJsEventLoopDelayAttributes.max]: {
4040
description: 'Event loop maximum delay.',
4141
},
42-
[NodeJsEventLoopDelay.mean]: {
42+
[NodeJsEventLoopDelayAttributes.mean]: {
4343
description: 'Event loop mean delay.',
4444
},
45-
[NodeJsEventLoopDelay.stddev]: {
45+
[NodeJsEventLoopDelayAttributes.stddev]: {
4646
description: 'Event loop standard deviation delay.',
4747
},
48-
[NodeJsEventLoopDelay.p50]: {
48+
[NodeJsEventLoopDelayAttributes.p50]: {
4949
description: 'Event loop 50 percentile delay.',
5050
},
51-
[NodeJsEventLoopDelay.p90]: {
51+
[NodeJsEventLoopDelayAttributes.p90]: {
5252
description: 'Event loop 90 percentile delay.',
5353
},
54-
[NodeJsEventLoopDelay.p99]: {
54+
[NodeJsEventLoopDelayAttributes.p99]: {
5555
description: 'Event loop 99 percentile delay.',
5656
},
5757
};
@@ -81,51 +81,51 @@ export class EventLoopDelayCollector extends BaseCollector {
8181

8282
updateMetricInstruments(meter: Meter): void {
8383
const delayMin = meter.createObservableGauge(
84-
`${this.namePrefix}.${NodeJsEventLoopDelay.min}`,
84+
`${this.namePrefix}.${NodeJsEventLoopDelayAttributes.min}`,
8585
{
86-
description: metricNames[NodeJsEventLoopDelay.min].description,
86+
description: metricNames[NodeJsEventLoopDelayAttributes.min].description,
8787
unit: 's',
8888
}
8989
);
9090
const delayMax = meter.createObservableGauge(
91-
`${this.namePrefix}.${NodeJsEventLoopDelay.max}`,
91+
`${this.namePrefix}.${NodeJsEventLoopDelayAttributes.max}`,
9292
{
93-
description: metricNames[NodeJsEventLoopDelay.max].description,
93+
description: metricNames[NodeJsEventLoopDelayAttributes.max].description,
9494
unit: 's',
9595
}
9696
);
9797
const delayMean = meter.createObservableGauge(
98-
`${this.namePrefix}.${NodeJsEventLoopDelay.mean}`,
98+
`${this.namePrefix}.${NodeJsEventLoopDelayAttributes.mean}`,
9999
{
100-
description: metricNames[NodeJsEventLoopDelay.mean].description,
100+
description: metricNames[NodeJsEventLoopDelayAttributes.mean].description,
101101
unit: 's',
102102
}
103103
);
104104
const delayStddev = meter.createObservableGauge(
105-
`${this.namePrefix}.${NodeJsEventLoopDelay.stddev}`,
105+
`${this.namePrefix}.${NodeJsEventLoopDelayAttributes.stddev}`,
106106
{
107-
description: metricNames[NodeJsEventLoopDelay.stddev].description,
107+
description: metricNames[NodeJsEventLoopDelayAttributes.stddev].description,
108108
unit: 's',
109109
}
110110
);
111111
const delayp50 = meter.createObservableGauge(
112-
`${this.namePrefix}.${NodeJsEventLoopDelay.p50}`,
112+
`${this.namePrefix}.${NodeJsEventLoopDelayAttributes.p50}`,
113113
{
114-
description: metricNames[NodeJsEventLoopDelay.p50].description,
114+
description: metricNames[NodeJsEventLoopDelayAttributes.p50].description,
115115
unit: 's',
116116
}
117117
);
118118
const delayp90 = meter.createObservableGauge(
119-
`${this.namePrefix}.${NodeJsEventLoopDelay.p90}`,
119+
`${this.namePrefix}.${NodeJsEventLoopDelayAttributes.p90}`,
120120
{
121-
description: metricNames[NodeJsEventLoopDelay.p90].description,
121+
description: metricNames[NodeJsEventLoopDelayAttributes.p90].description,
122122
unit: 's',
123123
}
124124
);
125125
const delayp99 = meter.createObservableGauge(
126-
`${this.namePrefix}.${NodeJsEventLoopDelay.p99}`,
126+
`${this.namePrefix}.${NodeJsEventLoopDelayAttributes.p99}`,
127127
{
128-
description: metricNames[NodeJsEventLoopDelay.p99].description,
128+
description: metricNames[NodeJsEventLoopDelayAttributes.p99].description,
129129
unit: 's',
130130
}
131131
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { BaseCollector } from './baseCollector';
2020

2121
const { eventLoopUtilization: eventLoopUtilizationCollector } = performance;
2222

23-
export const NODEJS_EVENT_LOOP_TIME = 'eventloop.time';
23+
export const ATTR_NODEJS_EVENT_LOOP_TIME = 'eventloop.time';
2424

2525
export class EventLoopTimeCollector extends BaseCollector {
2626
constructor(
@@ -32,7 +32,7 @@ export class EventLoopTimeCollector extends BaseCollector {
3232

3333
public updateMetricInstruments(meter: Meter): void {
3434
const timeCounter = meter.createObservableCounter(
35-
`${this.namePrefix}.${NODEJS_EVENT_LOOP_TIME}`,
35+
`${this.namePrefix}.${ATTR_NODEJS_EVENT_LOOP_TIME}`,
3636
{
3737
description:
3838
'Cumulative duration of time the event loop has been in each state.',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { BaseCollector } from './baseCollector';
2020

2121
const { eventLoopUtilization: eventLoopUtilizationCollector } = performance;
2222

23-
export const NODEJS_EVENT_LOOP_UTILIZATION = 'eventloop.utilization';
23+
export const ATTR_NODEJS_EVENT_LOOP_UTILIZATION = 'eventloop.utilization';
2424

2525
export class EventLoopUtilizationCollector extends BaseCollector {
2626
private _lastValue?: EventLoopUtilization;
@@ -35,7 +35,7 @@ export class EventLoopUtilizationCollector extends BaseCollector {
3535
public updateMetricInstruments(meter: Meter): void {
3636
meter
3737
.createObservableGauge(
38-
`${this.namePrefix}.${NODEJS_EVENT_LOOP_UTILIZATION}`,
38+
`${this.namePrefix}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION}`,
3939
{
4040
description: 'Event loop utilization',
4141
unit: 's',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { BaseCollector } from './baseCollector';
2020
import * as perf_hooks from 'node:perf_hooks';
2121
import { PerformanceObserver } from 'node:perf_hooks';
2222

23-
const NODEJS_GC_DURATION_SECONDS = 'gc.duration';
23+
const ATTR_NODEJS_GC_DURATION_SECONDS = 'gc.duration';
2424
const DEFAULT_GC_DURATION_BUCKETS = [0.01, 0.1, 1, 10];
2525

2626
const kinds: string[] = [];
@@ -57,7 +57,7 @@ export class GCCollector extends BaseCollector {
5757

5858
updateMetricInstruments(meter: Meter): void {
5959
this._gcDurationByKindHistogram = meter.createHistogram(
60-
`${this.namePrefix}.${NODEJS_GC_DURATION_SECONDS}`,
60+
`${this.namePrefix}.${ATTR_NODEJS_GC_DURATION_SECONDS}`,
6161
{
6262
description:
6363
'Garbage collection duration by kind, one of major, minor, incremental or weakcb.',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ 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_NAME_ATTRIBUTE } from '../consts/attributes';
21+
import { ATTR_V8JS_HEAP_SPACE_NAME } from '../consts/attributes';
2222

2323
export enum V8HeapSpaceMetrics {
2424
heapLimit = 'memory.heap.limit',
@@ -80,7 +80,7 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector {
8080
unit: 'By',
8181
}
8282
);
83-
const heapSpaceNameAttributeName = `${this.namePrefix}.${V8_HEAP_SIZE_NAME_ATTRIBUTE}`;
83+
const heapSpaceNameAttributeName = `${this.namePrefix}.${ATTR_V8JS_HEAP_SPACE_NAME}`;
8484

8585
meter.addBatchObservableCallback(
8686
observableResult => {

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

plugins/node/instrumentation-runtime-node/test/event_loop_time.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import { RuntimeNodeInstrumentation } from '../src';
1919
import * as assert from 'assert';
2020
import { TestMetricReader } from './testMetricsReader';
2121
import { ConventionalNamePrefix } from '../src/types/ConventionalNamePrefix';
22-
import { NODEJS_EVENT_LOOP_TIME } from '../src/metrics/eventLoopTimeCollector';
22+
import { ATTR_NODEJS_EVENT_LOOP_TIME } from '../src/metrics/eventLoopTimeCollector';
2323

2424
const MEASUREMENT_INTERVAL = 10;
2525

26-
describe(`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_TIME}`, function () {
26+
describe(`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_TIME}`, function () {
2727
let metricReader: TestMetricReader;
2828
let meterProvider: MeterProvider;
2929

@@ -51,7 +51,7 @@ describe(`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_TIME}`, function
5151
assert.strictEqual(scopeMetrics.length, 0);
5252
});
5353

54-
it(`should write ${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_TIME}`, async function () {
54+
it(`should write ${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_TIME}`, async function () {
5555
// arrange
5656
const instrumentation = new RuntimeNodeInstrumentation({
5757
monitoringPrecision: MEASUREMENT_INTERVAL,
@@ -72,14 +72,14 @@ describe(`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_TIME}`, function
7272
const timeMetric = scopeMetrics[0].metrics.find(
7373
x =>
7474
x.descriptor.name ===
75-
`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_TIME}`
75+
`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_TIME}`
7676
);
7777

7878
assert.notEqual(timeMetric, undefined, 'metric not found');
7979

8080
assert.strictEqual(
8181
timeMetric!.descriptor.name,
82-
`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_TIME}`,
82+
`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_TIME}`,
8383
'descriptor.name'
8484
);
8585

plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import { RuntimeNodeInstrumentation } from '../src';
1919
import * as assert from 'assert';
2020
import { TestMetricReader } from './testMetricsReader';
2121
import { ConventionalNamePrefix } from '../src/types/ConventionalNamePrefix';
22-
import { NODEJS_EVENT_LOOP_UTILIZATION } from '../src/metrics/eventLoopUtilizationCollector';
22+
import { ATTR_NODEJS_EVENT_LOOP_UTILIZATION } from '../src/metrics/eventLoopUtilizationCollector';
2323

2424
const MEASUREMENT_INTERVAL = 10;
2525

26-
describe(`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_UTILIZATION}`, function () {
26+
describe(`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION}`, function () {
2727
let metricReader: TestMetricReader;
2828
let meterProvider: MeterProvider;
2929

@@ -51,7 +51,7 @@ describe(`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_UTILIZATION}`, fu
5151
assert.strictEqual(scopeMetrics.length, 0);
5252
});
5353

54-
it(`should write ${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_UTILIZATION}`, async function () {
54+
it(`should write ${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION}`, async function () {
5555
// arrange
5656
const instrumentation = new RuntimeNodeInstrumentation({
5757
monitoringPrecision: MEASUREMENT_INTERVAL,
@@ -72,14 +72,14 @@ describe(`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_UTILIZATION}`, fu
7272
const utilizationMetric = scopeMetrics[0].metrics.find(
7373
x =>
7474
x.descriptor.name ===
75-
`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_UTILIZATION}`
75+
`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION}`
7676
);
7777

7878
assert.notEqual(utilizationMetric, undefined, 'metric not found');
7979

8080
assert.strictEqual(
8181
utilizationMetric!.descriptor.name,
82-
`${ConventionalNamePrefix.NodeJs}.${NODEJS_EVENT_LOOP_UTILIZATION}`,
82+
`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION}`,
8383
'descriptor.name'
8484
);
8585

0 commit comments

Comments
 (0)