diff --git a/examples/package-lock.json b/examples/package-lock.json index 3bac6b7e..cde58e98 100644 --- a/examples/package-lock.json +++ b/examples/package-lock.json @@ -18,6 +18,7 @@ "../packages/opentelemetry-node": { "name": "@elastic/opentelemetry-node", "version": "0.3.0", + "dev": true, "license": "Apache-2.0", "dependencies": { "@opentelemetry/exporter-logs-otlp-grpc": "^0.53.0", @@ -26,7 +27,6 @@ "@opentelemetry/exporter-metrics-otlp-grpc": "^0.53.0", "@opentelemetry/exporter-metrics-otlp-http": "^0.53.0", "@opentelemetry/exporter-metrics-otlp-proto": "^0.53.0", - "@opentelemetry/host-metrics": "^0.35.0", "@opentelemetry/instrumentation": "^0.53.0", "@opentelemetry/instrumentation-aws-sdk": "^0.44.0", "@opentelemetry/instrumentation-bunyan": "^0.41.0", @@ -54,6 +54,7 @@ "@opentelemetry/instrumentation-redis-4": "^0.42.0", "@opentelemetry/instrumentation-restify": "^0.41.0", "@opentelemetry/instrumentation-router": "^0.40.0", + "@opentelemetry/instrumentation-runtime-node": "file:../../../../otel/opentelemetry-js-contrib/plugins/node/instrumentation-runtime-node", "@opentelemetry/instrumentation-socket.io": "^0.42.0", "@opentelemetry/instrumentation-tedious": "^0.14.0", "@opentelemetry/instrumentation-undici": "^0.6.0", @@ -1018,7 +1019,6 @@ "@opentelemetry/exporter-metrics-otlp-grpc": "^0.53.0", "@opentelemetry/exporter-metrics-otlp-http": "^0.53.0", "@opentelemetry/exporter-metrics-otlp-proto": "^0.53.0", - "@opentelemetry/host-metrics": "^0.35.0", "@opentelemetry/instrumentation": "^0.53.0", "@opentelemetry/instrumentation-aws-sdk": "^0.44.0", "@opentelemetry/instrumentation-bunyan": "^0.41.0", @@ -1046,6 +1046,7 @@ "@opentelemetry/instrumentation-redis-4": "^0.42.0", "@opentelemetry/instrumentation-restify": "^0.41.0", "@opentelemetry/instrumentation-router": "^0.40.0", + "@opentelemetry/instrumentation-runtime-node": "file:../../../../otel/opentelemetry-js-contrib/plugins/node/instrumentation-runtime-node", "@opentelemetry/instrumentation-socket.io": "^0.42.0", "@opentelemetry/instrumentation-tedious": "^0.14.0", "@opentelemetry/instrumentation-undici": "^0.6.0", diff --git a/packages/opentelemetry-node/lib/elastic-node-sdk.js b/packages/opentelemetry-node/lib/elastic-node-sdk.js index 076c4a00..77369b8b 100644 --- a/packages/opentelemetry-node/lib/elastic-node-sdk.js +++ b/packages/opentelemetry-node/lib/elastic-node-sdk.js @@ -123,9 +123,9 @@ class ElasticNodeSDK extends NodeSDK { exportIntervalMillis: metricsInterval, exportTimeoutMillis: metricsTimeout, }); - defaultConfig.views = [ - // Add views for `host-metrics` to avoid excess of data being sent to the server - ...HOST_METRICS_VIEWS, + defaultConfig.views = [ + // Add views for `host-metrics` to avoid excess of data being sent to the server + ...HOST_METRICS_VIEWS, ]; } @@ -160,9 +160,9 @@ class ElasticNodeSDK extends NodeSDK { ); super.start(); - if (!this._metricsDisabled) { - // TODO: make this configurable, user might collect host metrics with a separate utility - enableHostMetrics(); + if (!this._metricsDisabled) { + // TODO: make this configurable, user might collect host metrics with a separate utility + enableHostMetrics(); } } } diff --git a/packages/opentelemetry-node/lib/instrumentations.js b/packages/opentelemetry-node/lib/instrumentations.js index 00169a64..65956d19 100644 --- a/packages/opentelemetry-node/lib/instrumentations.js +++ b/packages/opentelemetry-node/lib/instrumentations.js @@ -50,6 +50,7 @@ * "@opentelemetry/instrumentation-redis-4": import('@opentelemetry/instrumentation-redis-4').RedisInstrumentationConfig | InstrumentationFactory, * "@opentelemetry/instrumentation-restify": import('@opentelemetry/instrumentation-restify').RestifyInstrumentationConfig | InstrumentationFactory, * "@opentelemetry/instrumentation-router": import('@opentelemetry/instrumentation').InstrumentationConfig | InstrumentationFactory, + * "@opentelemetry/instrumentation-runtime-node": import('@opentelemetry/instrumentation-runtime-node').RuntimeNodeInstrumentationConfig | InstrumentationFactory, * "@opentelemetry/instrumentation-socket.io": import('@opentelemetry/instrumentation-socket.io').SocketIoInstrumentationConfig | InstrumentationFactory, * "@opentelemetry/instrumentation-tedious": import('@opentelemetry/instrumentation-tedious').TediousInstrumentationConfig | InstrumentationFactory, * "@opentelemetry/instrumentation-undici": import('@opentelemetry/instrumentation-undici').UndiciInstrumentationConfig | InstrumentationFactory, @@ -84,6 +85,7 @@ const {RedisInstrumentation} = require('@opentelemetry/instrumentation-redis'); const {RedisInstrumentation: RedisFourInstrumentation} = require('@opentelemetry/instrumentation-redis-4'); const {RestifyInstrumentation} = require('@opentelemetry/instrumentation-restify'); const {RouterInstrumentation} = require('@opentelemetry/instrumentation-router'); +const {RuntimeNodeInstrumentation} = require('@opentelemetry/instrumentation-runtime-node'); const {SocketIoInstrumentation} = require('@opentelemetry/instrumentation-socket.io'); const {TediousInstrumentation} = require('@opentelemetry/instrumentation-tedious'); const {UndiciInstrumentation} = require('@opentelemetry/instrumentation-undici'); @@ -126,6 +128,7 @@ const INSTRUMENTATIONS = { '@opentelemetry/instrumentation-redis-4': (cfg) => new RedisFourInstrumentation(cfg), '@opentelemetry/instrumentation-restify': (cfg) => new RestifyInstrumentation(cfg), '@opentelemetry/instrumentation-router': (cfg) => new RouterInstrumentation(cfg), + '@opentelemetry/instrumentation-runtime-node': (cfg) => new RuntimeNodeInstrumentation(cfg), '@opentelemetry/instrumentation-socket.io': (cfg) => new SocketIoInstrumentation(cfg), '@opentelemetry/instrumentation-tedious': (cfg) => new TediousInstrumentation(cfg), '@opentelemetry/instrumentation-undici': (cfg) => new UndiciInstrumentation(cfg), @@ -232,6 +235,13 @@ function getInstrumentations(opts = {}) { return; } + // Skip if metrics are disabled by env var + const isMetricsDisabled = + process.env.ELASTIC_OTEL_METRICS_DISABLED === 'true'; + if (isMetricsDisabled && name === '@opentelemetry/instrumentation-runtime-node') { + return; + } + const isFactory = typeof opts[name] === 'function'; const isObject = typeof opts[name] === 'object'; const instrFactory = isFactory ? opts[name] : INSTRUMENTATIONS[name]; diff --git a/packages/opentelemetry-node/lib/metrics/host.js b/packages/opentelemetry-node/lib/metrics/host.js index 4eaefcf8..7a690513 100644 --- a/packages/opentelemetry-node/lib/metrics/host.js +++ b/packages/opentelemetry-node/lib/metrics/host.js @@ -36,19 +36,11 @@ function enableHostMetrics() { // Ref (metrics in Kibana): https://github.com/elastic/kibana/pull/174700 /** @type {metrics.View[]} */ const HOST_METRICS_VIEWS = [ - // drop `system.network.*` (not in Kibana) + // TODO: As for now we're going to drop all system metrics + // - most of them are not in the classic agent + // - `system.cpu` and `system.memory` are recommended to use the collector new View({ - instrumentName: 'system.network.*', - aggregation: Aggregation.Drop(), - }), - // drop `system.cpu.time` (not in Kibana) - new View({ - instrumentName: 'system.cpu.time', - aggregation: Aggregation.Drop(), - }), - // drop `process.*` (not in Kibana) - new View({ - instrumentName: 'process.*', + instrumentName: 'system.*', aggregation: Aggregation.Drop(), }), ]; @@ -56,4 +48,4 @@ const HOST_METRICS_VIEWS = [ module.exports = { HOST_METRICS_VIEWS, enableHostMetrics, -}; +}; \ No newline at end of file diff --git a/packages/opentelemetry-node/package-lock.json b/packages/opentelemetry-node/package-lock.json index e082e29d..253e6aa6 100644 --- a/packages/opentelemetry-node/package-lock.json +++ b/packages/opentelemetry-node/package-lock.json @@ -43,6 +43,7 @@ "@opentelemetry/instrumentation-redis-4": "^0.42.0", "@opentelemetry/instrumentation-restify": "^0.41.0", "@opentelemetry/instrumentation-router": "^0.40.0", + "@opentelemetry/instrumentation-runtime-node": "file:../../../../otel/opentelemetry-js-contrib/plugins/node/instrumentation-runtime-node", "@opentelemetry/instrumentation-socket.io": "^0.42.0", "@opentelemetry/instrumentation-tedious": "^0.14.0", "@opentelemetry/instrumentation-undici": "^0.6.0", @@ -89,6 +90,31 @@ "node": ">=14.18.0" } }, + "../../../../otel/opentelemetry-js-contrib/plugins/node/instrumentation-runtime-node": { + "name": "@opentelemetry/instrumentation-runtime-node", + "version": "0.7.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/instrumentation": "^0.53.0" + }, + "devDependencies": { + "@opentelemetry/api": "^1.3.0", + "@opentelemetry/sdk-metrics": "^1.20.0", + "@types/mocha": "^10.0.6", + "@types/node": "18.18.14", + "mocha": "7.2.0", + "nyc": "^15.1.0", + "rimraf": "5.0.10", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + }, + "engines": { + "node": ">=17.4.0" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.3.0" + } + }, "../mockotlpserver": { "name": "@elastic/mockotlpserver", "version": "0.5.0", @@ -2716,6 +2742,10 @@ "@opentelemetry/api": "^1.3.0" } }, + "node_modules/@opentelemetry/instrumentation-runtime-node": { + "resolved": "../../../../otel/opentelemetry-js-contrib/plugins/node/instrumentation-runtime-node", + "link": true + }, "node_modules/@opentelemetry/instrumentation-socket.io": { "version": "0.42.0", "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-socket.io/-/instrumentation-socket.io-0.42.0.tgz", @@ -10386,6 +10416,21 @@ "@opentelemetry/semantic-conventions": "^1.27.0" } }, + "@opentelemetry/instrumentation-runtime-node": { + "version": "file:../../../../otel/opentelemetry-js-contrib/plugins/node/instrumentation-runtime-node", + "requires": { + "@opentelemetry/api": "^1.3.0", + "@opentelemetry/instrumentation": "^0.53.0", + "@opentelemetry/sdk-metrics": "^1.20.0", + "@types/mocha": "^10.0.6", + "@types/node": "18.18.14", + "mocha": "7.2.0", + "nyc": "^15.1.0", + "rimraf": "5.0.10", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + } + }, "@opentelemetry/instrumentation-socket.io": { "version": "0.42.0", "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-socket.io/-/instrumentation-socket.io-0.42.0.tgz", diff --git a/packages/opentelemetry-node/package.json b/packages/opentelemetry-node/package.json index 017c100a..9c9ef69d 100644 --- a/packages/opentelemetry-node/package.json +++ b/packages/opentelemetry-node/package.json @@ -98,6 +98,7 @@ "@opentelemetry/instrumentation-redis-4": "^0.42.0", "@opentelemetry/instrumentation-restify": "^0.41.0", "@opentelemetry/instrumentation-router": "^0.40.0", + "@opentelemetry/instrumentation-runtime-node": "file:../../../../otel/opentelemetry-js-contrib/plugins/node/instrumentation-runtime-node", "@opentelemetry/instrumentation-socket.io": "^0.42.0", "@opentelemetry/instrumentation-tedious": "^0.14.0", "@opentelemetry/instrumentation-undici": "^0.6.0", diff --git a/packages/opentelemetry-node/test/host-metrics.test.js b/packages/opentelemetry-node/test/host-metrics.test.js index 90bcc16d..9bc278e6 100644 --- a/packages/opentelemetry-node/test/host-metrics.test.js +++ b/packages/opentelemetry-node/test/host-metrics.test.js @@ -114,4 +114,4 @@ const testFixtures = [ test('host metrics', (suite) => { runTestFixtures(suite, testFixtures); suite.end(); -}); +}); \ No newline at end of file