Skip to main content
The dedicated opentelemetry-prometheus crate has been discontinued as of version 0.29. It depends on an unmaintained protobuf crate with known security vulnerabilities.
For Prometheus integration, use the OTLP exporter instead. Prometheus natively supports the OTLP protocol, providing a more stable, secure, and actively maintained solution.

Why OTLP?

  • Active maintenance: Part of the OpenTelemetry specification
  • Security: No dependency on unmaintained libraries
  • Native support: Prometheus 2.47+ has built-in OTLP receiver
  • Consistency: Same exporter works with multiple backends
  • Future-proof: Official OpenTelemetry standard

Quick Start

1. Run Prometheus with OTLP Support

Create a minimal prometheus.yml configuration:
Run Prometheus with OTLP receiver enabled:
Prometheus is now ready to accept OTLP metrics at: http://localhost:9090/api/v1/otlp/v1/metrics

2. Configure Your Application

Add dependencies to Cargo.toml:

3. Export Metrics to Prometheus

4. Query Metrics in Prometheus

Open the Prometheus web UI at http://localhost:9090 and query:
You should see your metrics with labels.

Complete Example with Multiple Metric Types

Migration from Old Prometheus Exporter

If you’re migrating from the discontinued opentelemetry-prometheus crate:

Before (Old Approach)

After (New Approach with OTLP)

Metric Types Mapping

OpenTelemetry metrics map to Prometheus as follows:

Naming Conventions

Follow Prometheus naming best practices:
Naming rules:
  • Use snake_case
  • Include unit suffix (_seconds, _bytes, _total)
  • Be descriptive and specific
  • Avoid redundant prefixes

Configuration

Custom Export Interval

By default, metrics are exported every 60 seconds. Customize this:

Resource Attributes

Add resource attributes that appear as labels:

Production Deployment

Using OpenTelemetry Collector

For production, use the OpenTelemetry Collector as an intermediary:
Run the collector:
Configure Prometheus to scrape the collector:
Update your application to send to the collector:
Benefits:
  • Buffering and retry logic
  • Multiple backend support
  • Metric transformation and filtering
  • Service discovery integration

Troubleshooting

Metrics Not Appearing

  1. Verify Prometheus OTLP receiver is enabled:
  2. Check endpoint URL:
    • Must include full path: /api/v1/otlp/v1/metrics
    • Default: http://localhost:9090/api/v1/otlp/v1/metrics
  3. Ensure shutdown is called:

Missing Labels

Ensure attributes are added when recording metrics:

Version Compatibility

Prometheus OTLP support requires:
  • Prometheus 2.47.0 or later
  • OpenTelemetry Rust SDK 0.20.0 or later

Legacy Prometheus Exporter (Deprecated)

This section is for reference only. The prometheus exporter is deprecated and should not be used in new projects.
The old opentelemetry-prometheus crate provided a pull-based exporter that exposed metrics via an HTTP endpoint. This approach is no longer recommended. For pull-based metrics, use the OpenTelemetry Collector with the Prometheus exporter as shown in the Production Deployment section.

Next Steps

OTLP Exporter

Learn more about OTLP configuration

Metrics Guide

Comprehensive guide to metrics in Rust