From 3c3e5f6962a740f81fbfd38d01376b1307e02751 Mon Sep 17 00:00:00 2001 From: legendecas Date: Mon, 25 Jul 2022 17:31:43 +0800 Subject: [PATCH 1/2] docs(prometheus-exporter): fix prometheus exporter examples in README --- experimental/examples/prometheus/package.json | 6 +++--- .../packages/opentelemetry-api-metrics/README.md | 12 ++++++------ .../opentelemetry-exporter-prometheus/README.md | 9 ++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/experimental/examples/prometheus/package.json b/experimental/examples/prometheus/package.json index a3c5dbca516..58a575558bc 100644 --- a/experimental/examples/prometheus/package.json +++ b/experimental/examples/prometheus/package.json @@ -1,6 +1,6 @@ { "name": "prometheus-example", - "version": "0.28.0", + "version": "0.30.0", "description": "Example of using @opentelemetry/sdk-metrics-base and @opentelemetry/exporter-prometheus", "main": "index.js", "scripts": { @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/api": "^1.0.2", - "@opentelemetry/exporter-prometheus": "0.28.0", - "@opentelemetry/sdk-metrics-base": "0.28.0" + "@opentelemetry/exporter-prometheus": "0.30.0", + "@opentelemetry/sdk-metrics-base": "0.30.0" } } diff --git a/experimental/packages/opentelemetry-api-metrics/README.md b/experimental/packages/opentelemetry-api-metrics/README.md index f922ed2e457..4aee4aebafb 100644 --- a/experimental/packages/opentelemetry-api-metrics/README.md +++ b/experimental/packages/opentelemetry-api-metrics/README.md @@ -38,12 +38,12 @@ const api = require("@opentelemetry/api-metrics"); const { MeterProvider } = require("@opentelemetry/sdk-metrics-base"); const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); -const meterProvider = new MeterProvider({ - // The Prometheus exporter runs an HTTP server which - // the Prometheus backend scrapes to collect metrics. - exporter: new PrometheusExporter({ startServer: true }), - interval: 1000, -}); +// The Prometheus exporter runs an HTTP server which the Prometheus backend +// scrapes to collect metrics. +const exporter = new PrometheusExporter({ startServer: true }); +// Creates MeterProvider and installs the exporter as a MetricReader +const meterProvider = new MeterProvider(); +meterProvider.addMetricReader(exporter); /** * Registering the provider with the API allows it to be discovered diff --git a/experimental/packages/opentelemetry-exporter-prometheus/README.md b/experimental/packages/opentelemetry-exporter-prometheus/README.md index f16f8a19635..1842ce156fb 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/README.md +++ b/experimental/packages/opentelemetry-exporter-prometheus/README.md @@ -26,11 +26,10 @@ const { MeterProvider } = require('@opentelemetry/sdk-metrics-base'); const options = {port: 9464, startServer: true}; const exporter = new PrometheusExporter(options); -// Register the exporter -const meter = new MeterProvider({ - exporter, - interval: 1000, -}).getMeter('example-prometheus'); +// Creates MeterProvider and installs the exporter as a MetricReader +const meterProvider = new MeterProvider(); +meterProvider.addMetricReader(exporter); +const meter = meterProvider.getMeter('example-prometheus'); // Now, start recording data const counter = meter.createCounter('metric_name', { From b0de445ce522988bf057fbb91c8604f6e44c3b6f Mon Sep 17 00:00:00 2001 From: legendecas Date: Tue, 16 Aug 2022 10:16:36 +0800 Subject: [PATCH 2/2] fixup! revert changes in experimental/examples --- experimental/examples/prometheus/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/experimental/examples/prometheus/package.json b/experimental/examples/prometheus/package.json index 58a575558bc..a3c5dbca516 100644 --- a/experimental/examples/prometheus/package.json +++ b/experimental/examples/prometheus/package.json @@ -1,6 +1,6 @@ { "name": "prometheus-example", - "version": "0.30.0", + "version": "0.28.0", "description": "Example of using @opentelemetry/sdk-metrics-base and @opentelemetry/exporter-prometheus", "main": "index.js", "scripts": { @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/api": "^1.0.2", - "@opentelemetry/exporter-prometheus": "0.30.0", - "@opentelemetry/sdk-metrics-base": "0.30.0" + "@opentelemetry/exporter-prometheus": "0.28.0", + "@opentelemetry/sdk-metrics-base": "0.28.0" } }