opentelemetry-prometheus
Version: 0.31.1
This crate is deprecated and no longer maintained. Development has been discontinued as of version 0.29. This crate has unresolved security vulnerabilities due to dependencies on the unmaintained protobuf crate.
Recommended Alternative
For Prometheus integration, use the OTLP exporter instead . Prometheus natively supports OTLP since version 2.47.0, providing a more stable and actively maintained solution.
Migration to OTLP
Before (Deprecated):
use opentelemetry_prometheus :: exporter;
let registry = prometheus :: Registry :: new ();
let exporter = exporter ()
. with_registry ( registry . clone ())
. build () ? ;
After (Recommended):
use opentelemetry_otlp :: { MetricExporter , Protocol , WithExportConfig };
// Start Prometheus with OTLP receiver enabled
// docker run -p 9090:9090 \
// -v ./prometheus.yml:/etc/prometheus/prometheus.yml \
// prom/prometheus --config.file=/etc/prometheus/prometheus.yml \
// --web.enable-otlp-receiver
let exporter = MetricExporter :: builder ()
. with_http ()
. with_protocol ( Protocol :: HttpBinary )
. with_endpoint ( "http://localhost:9090/api/v1/otlp/v1/metrics" )
. build () ? ;
let provider = opentelemetry_sdk :: metrics :: SdkMeterProvider :: builder ()
. with_periodic_exporter ( exporter )
. build ();
Legacy Documentation
Show legacy documentation (not recommended)
The opentelemetry-prometheus crate provided a Prometheus metrics exporter for OpenTelemetry. Installation (Legacy) [ dependencies ]
opentelemetry-prometheus = "0.31"
prometheus = "0.14"
Basic Usage (Legacy) use opentelemetry :: { metrics :: MeterProvider , KeyValue };
use opentelemetry_sdk :: metrics :: SdkMeterProvider ;
use prometheus :: { Encoder , TextEncoder };
let registry = prometheus :: Registry :: new ();
let exporter = opentelemetry_prometheus :: exporter ()
. with_registry ( registry . clone ())
. build () ? ;
let provider = SdkMeterProvider :: builder ()
. with_reader ( exporter )
. build ();
let meter = provider . meter ( "my-app" );
let counter = meter . u64_counter ( "requests" ) . build ();
counter . add ( 1 , & [ KeyValue :: new ( "path" , "/api" )]);
// Encode metrics for scraping
let encoder = TextEncoder :: new ();
let metric_families = registry . gather ();
let mut result = Vec :: new ();
encoder . encode ( & metric_families , & mut result ) ? ;
Key Types (Legacy) Exports OpenTelemetry metrics in Prometheus format
Builder for configuring the Prometheus exporter
Why Deprecated?
Security vulnerabilities - Depends on unmaintained protobuf crate
Better alternative exists - Prometheus now natively supports OTLP
No maintenance - The crate is no longer actively maintained
Specification alignment - OTLP is the recommended export protocol
Migration Resources
Prometheus OTLP Documentation Learn how to configure Prometheus to receive OTLP metrics
OTLP Exporter View documentation for the recommended OTLP exporter
Minimum Rust Version
MSRV: 1.75.0