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

[OpenTelemetry Prometheus Metric Exporter] Docs not working #3107

Closed
QuentinN42 opened this issue Jul 22, 2022 · 1 comment · Fixed by #3110
Closed

[OpenTelemetry Prometheus Metric Exporter] Docs not working #3107

QuentinN42 opened this issue Jul 22, 2022 · 1 comment · Fixed by #3110
Labels
bug Something isn't working document Documentation-related priority:p4 Bugs and spec inconsistencies which do not fall into a higher prioritization

Comments

@QuentinN42
Copy link

What happened?

Steps to Reproduce

Just follow the opentelemetry-exporter-prometheus README.

Expected Result

Some metrics.

Actual Result

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

OpenTelemetry Setup Code

import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { MeterProvider } from '@opentelemetry/sdk-metrics-base';
import fetch from 'node-fetch';

// Add your port and startServer to the Prometheus options
const options = {port: 9464, startServer: true};
const exporter = new PrometheusExporter(options);

// Register the exporter
const meter = new MeterProvider({
  exporter,
  interval: 1000,
}).getMeter('example-prometheus');

// Now, start recording data
const counter = meter.createCounter('metric_name', {
  description: 'Example of a counter'
});
counter.add(10, { pid: process.pid });

console.log("http://localhost:9464/metrics")

setTimeout(() => {
  fetch("http://localhost:9464/metrics").then(x => x.text()).then(console.log)
},
1000)

package.json

{
  "name": "js_prom_9roakq",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@opentelemetry/exporter-prometheus": "^0.30.0",
    "@opentelemetry/sdk-metrics-base": "^0.30.0",
    "node-fetch": "^3.2.9"
  }
}

Relevant log output

http://localhost:9464/metrics
# failed to export metrics: Error: MetricReader is not bound to a MetricProducer
@QuentinN42 QuentinN42 added bug Something isn't working triage labels Jul 22, 2022
@legendecas
Copy link
Member

Sorry about this. The document is outdated. You can check out https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/examples/prometheus/index.js for an example project for now.

@legendecas legendecas removed the triage label Jul 25, 2022
@dyladan dyladan added priority:p4 Bugs and spec inconsistencies which do not fall into a higher prioritization document Documentation-related labels Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working document Documentation-related priority:p4 Bugs and spec inconsistencies which do not fall into a higher prioritization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants