> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/open-telemetry/opentelemetry-rust/llms.txt
> Use this file to discover all available pages before exploring further.

# opentelemetry-prometheus

> Prometheus exporter for OpenTelemetry metrics (deprecated)

# opentelemetry-prometheus

**Version:** 0.31.1

<Warning>
  **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.
</Warning>

## Recommended Alternative

For Prometheus integration, **use the [OTLP exporter](/api/opentelemetry-otlp) instead**. Prometheus natively supports OTLP since version 2.47.0, providing a more stable and actively maintained solution.

### Migration to OTLP

**Before (Deprecated):**

```rust theme={null}
use opentelemetry_prometheus::exporter;

let registry = prometheus::Registry::new();
let exporter = exporter()
    .with_registry(registry.clone())
    .build()?;
```

**After (Recommended):**

```rust theme={null}
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

<Accordion title="Show legacy documentation (not recommended)">
  The `opentelemetry-prometheus` crate provided a Prometheus metrics exporter for OpenTelemetry.

  ### Installation (Legacy)

  ```toml theme={null}
  [dependencies]
  opentelemetry-prometheus = "0.31"
  prometheus = "0.14"
  ```

  ### Basic Usage (Legacy)

  ```rust theme={null}
  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)

  <ParamField path="PrometheusExporter" type="struct">
    Exports OpenTelemetry metrics in Prometheus format
  </ParamField>

  <ParamField path="ExporterBuilder" type="struct">
    Builder for configuring the Prometheus exporter
  </ParamField>
</Accordion>

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

<Card title="Prometheus OTLP Documentation" icon="arrow-up-right-from-square" href="https://prometheus.io/docs/guides/opentelemetry/">
  Learn how to configure Prometheus to receive OTLP metrics
</Card>

<Card title="OTLP Exporter" icon="cube" href="/api/opentelemetry-otlp">
  View documentation for the recommended OTLP exporter
</Card>

## Minimum Rust Version

**MSRV:** 1.75.0
