Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(otel-node): add node runtime metrics #416

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/opentelemetry-node/lib/elastic-node-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@
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 = [

Check failure on line 126 in packages/opentelemetry-node/lib/elastic-node-sdk.js

View workflow job for this annotation

GitHub Actions / lint

Delete `↹`
// Add views for `host-metrics` to avoid excess of data being sent to the server

Check failure on line 127 in packages/opentelemetry-node/lib/elastic-node-sdk.js

View workflow job for this annotation

GitHub Actions / lint

Delete `↹`
...HOST_METRICS_VIEWS,

Check failure on line 128 in packages/opentelemetry-node/lib/elastic-node-sdk.js

View workflow job for this annotation

GitHub Actions / lint

Delete `↹`
];
}

Expand Down Expand Up @@ -160,9 +160,9 @@
);
super.start();

if (!this._metricsDisabled) {
// TODO: make this configurable, user might collect host metrics with a separate utility
enableHostMetrics();
if (!this._metricsDisabled) {

Check failure on line 163 in packages/opentelemetry-node/lib/elastic-node-sdk.js

View workflow job for this annotation

GitHub Actions / lint

Delete `↹`
// TODO: make this configurable, user might collect host metrics with a separate utility

Check failure on line 164 in packages/opentelemetry-node/lib/elastic-node-sdk.js

View workflow job for this annotation

GitHub Actions / lint

Delete `↹`
enableHostMetrics();

Check failure on line 165 in packages/opentelemetry-node/lib/elastic-node-sdk.js

View workflow job for this annotation

GitHub Actions / lint

Delete `↹`
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/opentelemetry-node/lib/instrumentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,6 +85,7 @@
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');
Expand Down Expand Up @@ -126,6 +128,7 @@
'@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),
Expand Down Expand Up @@ -232,6 +235,13 @@
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') {

Check failure on line 241 in packages/opentelemetry-node/lib/instrumentations.js

View workflow job for this annotation

GitHub Actions / lint

Replace `isMetricsDisabled·&&·name·===·'@opentelemetry/instrumentation-runtime-node'` with `⏎············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];
Expand Down
18 changes: 5 additions & 13 deletions packages/opentelemetry-node/lib/metrics/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,16 @@
// 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(),
}),
];

module.exports = {
HOST_METRICS_VIEWS,
enableHostMetrics,
};
};

Check failure on line 51 in packages/opentelemetry-node/lib/metrics/host.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
45 changes: 45 additions & 0 deletions packages/opentelemetry-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/opentelemetry-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-node/test/host-metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@
test('host metrics', (suite) => {
runTestFixtures(suite, testFixtures);
suite.end();
});
});

Check failure on line 117 in packages/opentelemetry-node/test/host-metrics.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
Loading