How to expose metrics from sdk and HostMetrics to the same port? #5155
-
If possible I'm looking combine both metrics from the sdk and HostMetrics to be exposed at 9464/metrics With this implementation I get:
Is this possible? Thanks for the help in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, you're adding the exporter to two different Specifically Doing this instead should work: const prometheus = new PrometheusExporter();
const sdk = new NodeSDK({
metricReader: prometheus,
instrumentations: [
getNodeAutoInstrumentations(),
new RuntimeNodeInstrumentation(),
],
});
sdk.start();
import {metrics} from '@opentelemetry/api';
// important only get `MeterProvider` after `sdk.start()` otherwise it will be no-op.
const hostMetrics = new HostMetrics({ meterProvider: metrics.getMeterProvider() });
hostMetrics.start(); |
Beta Was this translation helpful? Give feedback.
Hi, you're adding the exporter to two different
MeterProvider
s, which is not supported.Specifically
NodeSDK
instantiates another instance ofMeterProvider
and tries to add thePrometheusExporter
to the new one but it was already bound on theMeterProvider
you created in L2-L4.Doing this instead should work: