@opentelemetry/instrumentation-runtime-node
Advanced tools
Comparing version 0.8.0 to 0.9.0
import { InstrumentationBase } from '@opentelemetry/instrumentation'; | ||
import { RuntimeNodeInstrumentationConfig } from './types'; | ||
export declare class RuntimeNodeInstrumentation extends InstrumentationBase<RuntimeNodeInstrumentationConfig> { | ||
private _ELUs; | ||
private _interval; | ||
private readonly _collectors; | ||
constructor(config?: RuntimeNodeInstrumentationConfig); | ||
private _addELU; | ||
private _clearELU; | ||
_updateMetricInstruments(): void; | ||
@@ -10,0 +7,0 @@ init(): void; |
@@ -19,10 +19,13 @@ "use strict"; | ||
*/ | ||
const node_perf_hooks_1 = require("node:perf_hooks"); | ||
const { eventLoopUtilization } = node_perf_hooks_1.performance; | ||
const instrumentation_1 = require("@opentelemetry/instrumentation"); | ||
const eventLoopUtilizationCollector_1 = require("./metrics/eventLoopUtilizationCollector"); | ||
const eventLoopDelayCollector_1 = require("./metrics/eventLoopDelayCollector"); | ||
const gcCollector_1 = require("./metrics/gcCollector"); | ||
const heapSpacesSizeAndUsedCollector_1 = require("./metrics/heapSpacesSizeAndUsedCollector"); | ||
const ConventionalNamePrefix_1 = require("./types/ConventionalNamePrefix"); | ||
const eventLoopTimeCollector_1 = require("./metrics/eventLoopTimeCollector"); | ||
/** @knipignore */ | ||
const version_1 = require("./version"); | ||
const ELUS_LENGTH = 2; | ||
const DEFAULT_CONFIG = { | ||
eventLoopUtilizationMeasurementInterval: 5000, | ||
monitoringPrecision: 10, | ||
}; | ||
@@ -32,31 +35,24 @@ class RuntimeNodeInstrumentation extends instrumentation_1.InstrumentationBase { | ||
super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, Object.assign({}, DEFAULT_CONFIG, config)); | ||
this._ELUs = []; | ||
} | ||
_addELU() { | ||
this._ELUs.unshift(eventLoopUtilization()); | ||
if (this._ELUs.length > ELUS_LENGTH) { | ||
this._ELUs.pop(); | ||
this._collectors = []; | ||
this._collectors = [ | ||
new eventLoopUtilizationCollector_1.EventLoopUtilizationCollector(this._config, ConventionalNamePrefix_1.ConventionalNamePrefix.NodeJs), | ||
new eventLoopTimeCollector_1.EventLoopTimeCollector(this._config, ConventionalNamePrefix_1.ConventionalNamePrefix.NodeJs), | ||
new eventLoopDelayCollector_1.EventLoopDelayCollector(this._config, ConventionalNamePrefix_1.ConventionalNamePrefix.NodeJs), | ||
new gcCollector_1.GCCollector(this._config, ConventionalNamePrefix_1.ConventionalNamePrefix.V8js), | ||
new heapSpacesSizeAndUsedCollector_1.HeapSpacesSizeAndUsedCollector(this._config, ConventionalNamePrefix_1.ConventionalNamePrefix.V8js), | ||
]; | ||
if (this._config.enabled) { | ||
for (const collector of this._collectors) { | ||
collector.enable(); | ||
} | ||
} | ||
} | ||
_clearELU() { | ||
if (!this._ELUs) { | ||
this._ELUs = []; | ||
} | ||
this._ELUs.length = 0; | ||
} | ||
// Called when a new `MeterProvider` is set | ||
// the Meter (result of @opentelemetry/api's getMeter) is available as this.meter within this method | ||
_updateMetricInstruments() { | ||
this.meter | ||
.createObservableGauge('nodejs.event_loop.utilization', { | ||
description: 'Event loop utilization', | ||
unit: '1', | ||
}) | ||
.addCallback(async (observableResult) => { | ||
if (this._ELUs.length !== ELUS_LENGTH) { | ||
return; | ||
} | ||
const elu = eventLoopUtilization(...this._ELUs); | ||
observableResult.observe(elu.utilization); | ||
}); | ||
if (!this._collectors) | ||
return; | ||
for (const collector of this._collectors) { | ||
collector.updateMetricInstruments(this.meter); | ||
} | ||
} | ||
@@ -67,14 +63,12 @@ init() { | ||
enable() { | ||
var _a; | ||
this._clearELU(); | ||
this._addELU(); | ||
clearInterval(this._interval); | ||
this._interval = setInterval(() => this._addELU(), this.getConfig().eventLoopUtilizationMeasurementInterval); | ||
// unref so that it does not keep the process running if disable() is never called | ||
(_a = this._interval) === null || _a === void 0 ? void 0 : _a.unref(); | ||
if (!this._collectors) | ||
return; | ||
for (const collector of this._collectors) { | ||
collector.enable(); | ||
} | ||
} | ||
disable() { | ||
this._clearELU(); | ||
clearInterval(this._interval); | ||
this._interval = undefined; | ||
for (const collector of this._collectors) { | ||
collector.disable(); | ||
} | ||
} | ||
@@ -81,0 +75,0 @@ } |
import type { InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
export interface RuntimeNodeInstrumentationConfig extends InstrumentationConfig { | ||
/** | ||
* 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. | ||
* @default 5000 | ||
*/ | ||
eventLoopUtilizationMeasurementInterval?: number; | ||
monitoringPrecision?: number; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export declare const PACKAGE_VERSION = "0.8.0"; | ||
export declare const PACKAGE_VERSION = "0.9.0"; | ||
export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-runtime-node"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,4 +20,4 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.PACKAGE_VERSION = '0.8.0'; | ||
exports.PACKAGE_VERSION = '0.9.0'; | ||
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-runtime-node'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-runtime-node", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "OpenTelemetry instrumentation for Node.js Performance measurement API", | ||
@@ -14,3 +14,2 @@ "main": "build/src/index.js", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-runtime-node --include-dependencies", | ||
"prewatch": "npm run precompile", | ||
@@ -24,3 +23,3 @@ "prepublishOnly": "npm run compile", | ||
"engines": { | ||
"node": ">=14.10.0" | ||
"node": ">=17.4.0" | ||
}, | ||
@@ -50,3 +49,4 @@ "keywords": [ | ||
"@types/mocha": "^10.0.6", | ||
"@types/node": "^20.11.2", | ||
"@types/node": "18.18.14", | ||
"mocha": "7.2.0", | ||
"nyc": "^15.1.0", | ||
@@ -59,3 +59,3 @@ "rimraf": "5.0.10", | ||
}, | ||
"gitHead": "7633caee19a7f04c5cc5e191d1ae7745ac3739f1" | ||
"gitHead": "acbaf200874cabe3f58334d38e91f1c2f1de4d6c" | ||
} |
@@ -35,3 +35,3 @@ # OpenTelemetry Node.js Runtime Metrics Instrumentation | ||
instrumentations: [new RuntimeNodeInstrumentation({ | ||
eventLoopUtilizationMeasurementInterval: 5000, | ||
monitoringPrecision: 5000, | ||
})], | ||
@@ -54,3 +54,3 @@ }); | ||
> Metrics will only be exported after it has collected two ELU readings (at least approximately `RuntimeNodeInstrumentationConfig.eventLoopUtilizationMeasurementInterval` milliseconds after initialization). Otherwise, you may see: | ||
> Metrics will only be exported after it has collected two ELU readings (at least approximately `RuntimeNodeInstrumentationConfig.monitoringPrecision` milliseconds after initialization). Otherwise, you may see: | ||
> | ||
@@ -66,4 +66,4 @@ > ```txt | ||
| name | type | unit | default | description | | ||
|---|---|---|---|---| | ||
| [`eventLoopUtilizationMeasurementInterval`](./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. | | ||
|---|---|---|---------|---| | ||
| [`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. | | ||
@@ -70,0 +70,0 @@ ## Useful links |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86326
42
653
8
1