The `opentelemetry-exporter-prometheus` library provides a Prometheus Metric Exporter for OpenTelemetry, allowing applications instrumented with OpenTelemetry to expose their metrics in a format that a Prometheus server can scrape. It is part of the larger OpenTelemetry Python project, currently at version 0.61b0, and is under active development with frequent releases.
pip install opentelemetry-exporter-prometheus opentelemetry-sdk prometheus_clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up the OpenTelemetry Prometheus Exporter. It initializes a `MeterProvider` with a `PrometheusMetricReader` which automatically starts an HTTP server on port 9464 (by default) that Prometheus can scrape. It then creates a simple counter and increments it periodically, exposing the metric for Prometheus to collect. Remember to set the `OTEL_SERVICE_NAME` environment variable for better metric identification.
Always pin to exact versions (`==x.y.z`) and review changelogs thoroughly during upgrades. Consider using the OpenTelemetry Collector for production environments if API stability is critical.
Be aware of the translation rules when querying metrics in Prometheus. Consult the OpenTelemetry documentation on Prometheus compatibility and metric naming normalization.
Ensure your OpenTelemetry SDK configuration for metrics uses cumulative temporality, which is often the default for OTLP export. Review temporality settings if metrics are missing or appear incorrect.
For production or larger scale environments, it is generally recommended to use an OpenTelemetry Collector. Applications can export metrics to the Collector via OTLP, and the Collector can then expose them to Prometheus via its own Prometheus exporter, offering more flexibility and control.
Ensure the default port 9464 is available. If not, configure a different port for the `PrometheusMetricReader` when initializing it, or for the `start_http_server` call if used directly.