Skip to main content

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.
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

Why Deprecated?

  1. Security vulnerabilities - Depends on unmaintained protobuf crate
  2. Better alternative exists - Prometheus now natively supports OTLP
  3. No maintenance - The crate is no longer actively maintained
  4. 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

Build docs developers (and LLMs) love