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

MetricReader is not bound to a MetricProducer #1014

Closed
Eomm opened this issue May 8, 2022 · 17 comments · Fixed by #1182
Closed

MetricReader is not bound to a MetricProducer #1014

Eomm opened this issue May 8, 2022 · 17 comments · Fixed by #1182
Assignees
Labels

Comments

@Eomm
Copy link
Contributor

Eomm commented May 8, 2022

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.

@Eomm Eomm added the bug Something isn't working label May 8, 2022
@Eomm
Copy link
Contributor Author

Eomm commented May 8, 2022

Digging a bit, I think it relates to #983

@legendecas
Copy link
Member

legendecas commented May 8, 2022

Metrics API is still experimental and we are working to adopt the latest metrics spec changes towards GA. From @opentelemetry/sdk-metrics-base v0.28.0, you'll need to apply the following changes the get the example in the OP working:

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

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

+ meterProvider.addMetricReader(exporter);

And the @opentelemetry/host-metrics that are compatible with sdk-metrics-base v0.28.0 is pending release: #947

@Eomm
Copy link
Contributor Author

Eomm commented May 10, 2022

Applying your suggestion leads to:

TypeError: meterProvider.addMetricProvider is not a function

My versions

├─┬ @opentelemetry/[email protected]
│ └── @opentelemetry/[email protected] deduped
├─┬ @opentelemetry/[email protected]
│ └── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
└─┬ @opentelemetry/[email protected]
  └── @opentelemetry/[email protected] deduped

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

@dyladan
Copy link
Member

dyladan commented May 10, 2022

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

yes

@Eomm
Copy link
Contributor Author

Eomm commented May 21, 2022

Is there any release plan?

@dyladan
Copy link
Member

dyladan commented May 23, 2022

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

@BakrFlow
Copy link

BakrFlow commented Jun 2, 2022

Is there any updates?, I still get the same error even with @opentelemetry/host-metrics v0.28

@Eomm
Copy link
Contributor Author

Eomm commented Jul 4, 2022

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2022

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Sep 5, 2022
@dyladan
Copy link
Member

dyladan commented Sep 14, 2022

@Eomm any update on if this is still an issue?

@Eomm
Copy link
Contributor Author

Eomm commented Sep 17, 2022

Just tried the doc example but same error for me by using node v16.x: https://www.npmjs.com/package/@opentelemetry/host-metrics

Switching to node.js v18.6.0 I get the same:

image

I wonder if it is an OS issue (I'm using mac os)

Deps:

    "@opentelemetry/api": "^1.2.0",
    "@opentelemetry/exporter-prometheus": "^0.33.0",
    "@opentelemetry/exporter-zipkin": "^1.7.0",
    "@opentelemetry/host-metrics": "^0.30.0",
    "@opentelemetry/instrumentation-dns": "^0.30.0",
    "@opentelemetry/instrumentation-fastify": "^0.29.0",
    "@opentelemetry/instrumentation-http": "^0.33.0",
    "@opentelemetry/instrumentation-mongodb": "^0.32.0",
    "@opentelemetry/sdk-metrics-base": "^0.31.0",
    "@opentelemetry/sdk-node": "^0.33.0",
    "@opentelemetry/semantic-conventions": "^1.7.0",

@legendecas
Copy link
Member

Would you mind updating the dependency opentelemetry/sdk-metrics-base with opentelemetry/sdk-metrics v0.33.0? It has been renamed in the recent release. Thank you!

@Eomm
Copy link
Contributor Author

Eomm commented Sep 18, 2022

Sure, but.. the same result.
Am I the only one that is facing this issue?

I have rm -rf node_modules and reinstalled only these packages:

    "@opentelemetry/exporter-prometheus": "^0.33.0",
    "@opentelemetry/host-metrics": "^0.30.0",
    "@opentelemetry/sdk-metrics": "^0.33.0",
    "@opentelemetry/sdk-node": "^0.33.0",

Here the code I'm running:

Click to expand!
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({
  exporter,
  interval: 2000
})

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

// const fastify = require('fastify')()
// fastify.listen(8080)
setInterval(() => { console.log('tick') }, 10000)

@legendecas
Copy link
Member

Sorry but you have to apply the patch mentioned at #1014 (comment) too.

@Eomm
Copy link
Contributor Author

Eomm commented Sep 19, 2022

Yeah, I did it, but I keep getting the is not a function error and the module is up to date:

$ npm ls @opentelemetry/sdk-metrics       
[email protected] /_experiments/prj
├─┬ @opentelemetry/[email protected]
│ └── @opentelemetry/[email protected] deduped
├─┬ @opentelemetry/[email protected]
│ └── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
└─┬ @opentelemetry/[email protected]
  └── @opentelemetry/[email protected] deduped

$ node prova.js                    
/_experiments/prj/prova.js:17
meterProvider.addMetricProvider(exporter)
              ^

TypeError: meterProvider.addMetricProvider is not a function
    at Object.<anonymous> (/_experiments/prj/prova.js:17:15)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

@legendecas
Copy link
Member

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()

@Eomm
Copy link
Contributor Author

Eomm commented Sep 19, 2022

Thanks, it works!
I should study a but the APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants