Skip to content

How to expose metrics from sdk and HostMetrics to the same port? #5155

Answered by pichlermarc
JessicaJHee asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, you're adding the exporter to two different MeterProviders, which is not supported.

Specifically NodeSDK instantiates another instance of MeterProviderand tries to add the PrometheusExporter to the new one but it was already bound on the MeterProvider you created in L2-L4.

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({ m…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JessicaJHee
Comment options

Answer selected by JessicaJHee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants