opentelemetry-js-contrib: MetricReader is not bound to a MetricProducer

What version of OpenTelemetry are you using?

    "@opentelemetry/api": "^1.1.0",
    "@opentelemetry/exporter-prometheus": "^0.28.0",
    "@opentelemetry/host-metrics": "^0.27.1",

What version of Node are you using?

v16.13.0

What did you do?

const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { HostMetrics } = require('@opentelemetry/host-metrics');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');

const exporter = new PrometheusExporter(
  {
    startServer: true
  }, () => {
    console.log('prometheus scrape endpoint: http://localhost:9464/metrics')
  }
)

const meterProvider = new MeterProvider({
  exporter,
  interval: 2000
})

const hostMetrics = new HostMetrics({ meterProvider, name: 'example-host-metrics' })
hostMetrics.start()

const fastify = require('fastify')()
fastify.listen(8080)

What did you expect to see?

Host metrics

What did you see instead?

By reaching the URL: http://localhost:9464/metrics I get:

# failed to export metrics: Error: MetricReader is not bound to a MetricProducer

Additional context

I was trying to add the HostMetrics to the opentelemetry.NodeSDK component, but unsuccessfully. So I tried the basic example, and I get the same error.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (16 by maintainers)

Most upvoted comments

Sorry, it’s not addMetricProvider but rather addMetricReader. The code snippet I use is as follows:

const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const { HostMetrics } = require('@opentelemetry/host-metrics');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');

const exporter = new PrometheusExporter(
  {
    startServer: true
  }, () => {
    console.log('prometheus scrape endpoint: http://localhost:9464/metrics')
  }
)

const meterProvider = new MeterProvider()
meterProvider.addMetricReader(exporter)

const hostMetrics = new HostMetrics({ meterProvider, name: 'example-host-metrics' })
hostMetrics.start()

I will get the chance to test it by my side on the next days

I’m cutting a release today sorry. The release automation failed while we were at kubecon and i’m looking into it

Should I wait for @opentelemetry/host-metrics v0.28?

yes