Skip to content

Commit dbb34ff

Browse files
committed
lint(instrumentation-runtime-node): lint
1 parent 926f052 commit dbb34ff

14 files changed

+292
-175
lines changed
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
export const NODE_JS_VERSION_ATTRIBUTE = "nodejsruntime.version"
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
export const NODE_JS_VERSION_ATTRIBUTE = 'nodejsruntime.version';
217
export const V8_HEAP_SIZE_STATE_ATTRIBUTE = 'heap.size.state';
318
export const V8_HEAP_SIZE = 'heap.size';

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ import { EventLoopDelayCollector } from './metrics/eventLoopDelayCollector';
2323
import { GCCollector } from './metrics/gcCollector';
2424
import { HeapSizeAndUsedCollector } from './metrics/heapSizeAndUsedCollector';
2525
import { HeapSpacesSizeAndUsedCollector } from './metrics/heapSpacesSizeAndUsedCollector';
26-
import {ConventionalNamePrefix} from "./types/ConventionalNamePrefix";
26+
import { ConventionalNamePrefix } from './types/ConventionalNamePrefix';
2727

2828
const DEFAULT_CONFIG: RuntimeNodeInstrumentationConfig = {
2929
monitoringPrecision: 5000,
3030
};
3131

32-
3332
export class RuntimeNodeInstrumentation extends InstrumentationBase {
3433
private _collectors: MetricCollector[] = [];
3534

@@ -40,11 +39,23 @@ export class RuntimeNodeInstrumentation extends InstrumentationBase {
4039
Object.assign({}, DEFAULT_CONFIG, config)
4140
);
4241
this._collectors = [
43-
new EventLoopUtilizationCollector(this._config, ConventionalNamePrefix.NodeJsRuntime),
44-
new EventLoopDelayCollector(this._config, ConventionalNamePrefix.NodeJsRuntime),
42+
new EventLoopUtilizationCollector(
43+
this._config,
44+
ConventionalNamePrefix.NodeJsRuntime
45+
),
46+
new EventLoopDelayCollector(
47+
this._config,
48+
ConventionalNamePrefix.NodeJsRuntime
49+
),
4550
new GCCollector(this._config, ConventionalNamePrefix.V8EnjineRuntime),
46-
new HeapSizeAndUsedCollector(this._config, ConventionalNamePrefix.V8EnjineRuntime),
47-
new HeapSpacesSizeAndUsedCollector(this._config, ConventionalNamePrefix.V8EnjineRuntime),
51+
new HeapSizeAndUsedCollector(
52+
this._config,
53+
ConventionalNamePrefix.V8EnjineRuntime
54+
),
55+
new HeapSpacesSizeAndUsedCollector(
56+
this._config,
57+
ConventionalNamePrefix.V8EnjineRuntime
58+
),
4859
];
4960
if (this._config.enabled) {
5061
for (const collector of this._collectors) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {MetricCollector} from '../types/metricCollector';
17-
import {Meter} from '@opentelemetry/api';
18-
import {clearInterval} from 'node:timers';
19-
import {RuntimeNodeInstrumentationConfig} from '../types';
20-
import {NODE_JS_VERSION_ATTRIBUTE} from "../consts/attributes";
16+
import { MetricCollector } from '../types/metricCollector';
17+
import { Meter } from '@opentelemetry/api';
18+
import { clearInterval } from 'node:timers';
19+
import { RuntimeNodeInstrumentationConfig } from '../types';
20+
import { NODE_JS_VERSION_ATTRIBUTE } from '../consts/attributes';
2121

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

2424
export abstract class BaseCollector<T> implements MetricCollector {
2525
protected _config: RuntimeNodeInstrumentationConfig = {};
2626

2727
protected namePrefix: string;
2828
private _interval: NodeJS.Timeout | undefined;
2929
protected _scrapeQueue: T[] = [];
30-
protected versionAttribute: VersionAttribute
30+
protected versionAttribute: VersionAttribute;
3131

3232
protected constructor(
3333
config: RuntimeNodeInstrumentationConfig = {},
3434
namePrefix: string
3535
) {
3636
this._config = config;
3737
this.namePrefix = namePrefix;
38-
this.versionAttribute = {[NODE_JS_VERSION_ATTRIBUTE]: process.version}
38+
this.versionAttribute = { [NODE_JS_VERSION_ATTRIBUTE]: process.version };
3939
}
4040

4141
public disable(): void {

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

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
import {RuntimeNodeInstrumentationConfig} from '../types';
1717
import {Meter} from '@opentelemetry/api';
18+
import * as perf_hooks from 'node:perf_hooks';
1819
import {IntervalHistogram} from 'node:perf_hooks';
1920
import {BaseCollector} from './baseCollector';
20-
import * as perf_hooks from 'node:perf_hooks';
2121

2222
enum NodeJsEventLoopDelay {
2323
delay = 'eventloop.delay',
@@ -27,48 +27,37 @@ enum NodeJsEventLoopDelay {
2727
stddev = 'eventloop.delay.stddev',
2828
p50 = 'eventloop.delay.p50',
2929
p90 = 'eventloop.delay.p90',
30-
p99 = 'eventloop.delay.p99'
30+
p99 = 'eventloop.delay.p99',
3131
}
3232

33-
export const metricNames: Record<NodeJsEventLoopDelay, { description: string }> = {
33+
export const metricNames: Record<
34+
NodeJsEventLoopDelay,
35+
{ description: string }
36+
> = {
3437
[NodeJsEventLoopDelay.delay]: {
35-
description:
36-
'Lag of event loop in seconds.'
37-
},
38+
description: 'Lag of event loop in seconds.',
39+
},
3840
[NodeJsEventLoopDelay.min]: {
39-
description:
40-
'The minimum recorded event loop delay.',
41-
},
41+
description: 'The minimum recorded event loop delay.',
42+
},
4243
[NodeJsEventLoopDelay.max]: {
43-
description:
44-
'The maximum recorded event loop delay.',
45-
}
46-
,
44+
description: 'The maximum recorded event loop delay.',
45+
},
4746
[NodeJsEventLoopDelay.mean]: {
48-
description:
49-
'The mean of the recorded event loop delays.',
50-
}
51-
,
47+
description: 'The mean of the recorded event loop delays.',
48+
},
5249
[NodeJsEventLoopDelay.stddev]: {
53-
description:
54-
'The standard deviation of the recorded event loop delays.',
55-
}
56-
,
50+
description: 'The standard deviation of the recorded event loop delays.',
51+
},
5752
[NodeJsEventLoopDelay.p50]: {
58-
description:
59-
'The 50th percentile of the recorded event loop delays.',
60-
}
61-
,
53+
description: 'The 50th percentile of the recorded event loop delays.',
54+
},
6255
[NodeJsEventLoopDelay.p90]: {
63-
description:
64-
'The 90th percentile of the recorded event loop delays.',
65-
}
66-
,
56+
description: 'The 90th percentile of the recorded event loop delays.',
57+
},
6758
[NodeJsEventLoopDelay.p99]: {
68-
description:
69-
'The 99th percentile of the recorded event loop delays.',
70-
}
71-
,
59+
description: 'The 99th percentile of the recorded event loop delays.',
60+
},
7261
};
7362

7463
export interface EventLoopLagInformation {
@@ -84,7 +73,6 @@ export interface EventLoopLagInformation {
8473
export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformation> {
8574
private _histogram: IntervalHistogram;
8675

87-
8876
constructor(
8977
config: RuntimeNodeInstrumentationConfig = {},
9078
namePrefix: string
@@ -160,25 +148,38 @@ export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformati
160148
const data = this._scrapeQueue.shift();
161149
if (data === undefined) return;
162150

163-
const start = process.hrtime();
151+
const startHrTime = process.hrtime();
164152
const delayResult = await new Promise<number>(res => {
165153
setImmediate((start: [number, number]) => {
166154
res(this._reportEventloopLag(start));
167-
}, start);
155+
}, startHrTime);
168156
});
169157

170158
observableResult.observe(delay, delayResult, this.versionAttribute);
171159
observableResult.observe(delayMin, data.min, this.versionAttribute);
172160
observableResult.observe(delayMax, data.max, this.versionAttribute);
173161
observableResult.observe(delayMean, data.mean, this.versionAttribute);
174-
observableResult.observe(delayStddev, data.stddev, this.versionAttribute);
162+
observableResult.observe(
163+
delayStddev,
164+
data.stddev,
165+
this.versionAttribute
166+
);
175167
observableResult.observe(delayp50, data.p50, this.versionAttribute);
176168
observableResult.observe(delayp90, data.p90, this.versionAttribute);
177169
observableResult.observe(delayp99, data.p99, this.versionAttribute);
178170

179171
this._histogram.reset();
180172
},
181-
[delay, delayMin, delayMax, delayMean, delayStddev, delayp50, delayp90, delayp99]
173+
[
174+
delay,
175+
delayMin,
176+
delayMax,
177+
delayMean,
178+
delayStddev,
179+
delayp50,
180+
delayp90,
181+
delayp99,
182+
]
182183
);
183184
}
184185

@@ -205,8 +206,7 @@ export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformati
205206
private _reportEventloopLag(start: [number, number]): number {
206207
const delta = process.hrtime(start);
207208
const nanosec = delta[0] * 1e9 + delta[1];
208-
const seconds = nanosec / 1e9;
209-
return seconds;
209+
return nanosec / 1e9;
210210
}
211211

212212
private checkNan(value: number) {

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
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 {Histogram, ValueType} from '@opentelemetry/api';
19-
import {BaseCollector} from './baseCollector';
16+
import { RuntimeNodeInstrumentationConfig } from '../types';
17+
import { Meter } from '@opentelemetry/api';
18+
import { Histogram, ValueType } from '@opentelemetry/api';
19+
import { BaseCollector } from './baseCollector';
2020
import * as perf_hooks from 'node:perf_hooks';
21-
import {PerformanceObserver} from 'node:perf_hooks';
21+
import { PerformanceObserver } from 'node:perf_hooks';
2222

2323
const NODEJS_GC_DURATION_SECONDS = 'gc.duration';
2424
const DEFAULT_GC_DURATION_BUCKETS = [0.01, 0.1, 1, 10];
@@ -43,11 +43,15 @@ export class GCCollector extends BaseCollector<null> {
4343
// Node < 16 uses entry.kind
4444
// Node >= 16 uses entry.detail.kind
4545
// See: https://nodejs.org/docs/latest-v16.x/api/deprecations.html#deprecations_dep0152_extension_performanceentry_properties
46+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4647
// @ts-ignore
4748
const kind = entry.detail ? kinds[entry.detail.kind] : kinds[entry.kind];
4849
this._gcDurationByKindHistogram?.record(
4950
entry.duration / 1000,
50-
Object.assign({ [`${this.namePrefix}.gc.type`]: kind }, this.versionAttribute)
51+
Object.assign(
52+
{ [`${this.namePrefix}.gc.type`]: kind },
53+
this.versionAttribute
54+
)
5155
);
5256
});
5357
}
@@ -68,7 +72,7 @@ export class GCCollector extends BaseCollector<null> {
6872
}
6973

7074
internalEnable(): void {
71-
this._observer.observe({entryTypes: ['gc']});
75+
this._observer.observe({ entryTypes: ['gc'] });
7276
}
7377

7478
internalDisable(): void {

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
import { RuntimeNodeInstrumentationConfig } from '../types';
1717
import { Meter } from '@opentelemetry/api';
1818
import { BaseCollector } from './baseCollector';
19-
import {HeapSizes} from "../types/heapSizes";
20-
import {V8_HEAP_SIZE, V8_HEAP_SIZE_STATE_ATTRIBUTE} from "../consts/attributes";
21-
19+
import { HeapSizes } from '../types/heapSizes';
20+
import {
21+
V8_HEAP_SIZE,
22+
V8_HEAP_SIZE_STATE_ATTRIBUTE,
23+
} from '../consts/attributes';
2224

2325
export class HeapSizeAndUsedCollector extends BaseCollector<NodeJS.MemoryUsage> {
2426
constructor(
@@ -29,26 +31,27 @@ export class HeapSizeAndUsedCollector extends BaseCollector<NodeJS.MemoryUsage>
2931
}
3032

3133
updateMetricInstruments(meter: Meter): void {
32-
meter.createObservableGauge(
33-
`${this.namePrefix}.${V8_HEAP_SIZE}`,
34-
{
35-
description: "Process heap size from Node.js in bytes.",
34+
meter
35+
.createObservableGauge(`${this.namePrefix}.${V8_HEAP_SIZE}`, {
36+
description: 'Process heap size from Node.js in bytes.',
3637
unit: 'By',
37-
}
38-
).addCallback(async observableResult => {
39-
if (this._scrapeQueue.length === 0) return;
38+
})
39+
.addCallback(async observableResult => {
40+
if (this._scrapeQueue.length === 0) return;
4041

41-
const data = this._scrapeQueue.shift();
42-
if (data === undefined) return;
43-
observableResult.observe(data.heapTotal, {
44-
[`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]: HeapSizes.Total,
45-
...this.versionAttribute
46-
});
47-
observableResult.observe(data.heapUsed, {
48-
[`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]: HeapSizes.Used,
49-
...this.versionAttribute
42+
const data = this._scrapeQueue.shift();
43+
if (data === undefined) return;
44+
observableResult.observe(data.heapTotal, {
45+
[`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]:
46+
HeapSizes.Total,
47+
...this.versionAttribute,
48+
});
49+
observableResult.observe(data.heapUsed, {
50+
[`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]:
51+
HeapSizes.Used,
52+
...this.versionAttribute,
53+
});
5054
});
51-
});
5255
}
5356

5457
internalEnable(): void {}

0 commit comments

Comments
 (0)