Prometheus Receiver
core, contrib, k8s
Maintainers: @Aneurysm9, @dashpole, @ArthurSens, @krajorama
Source: opentelemetry-collector-contrib
Supported Telemetry
Overview
See the Design for additional information on this receiver.⚠️ Warning
Note: This component is currently work in progress. It has several limitations and please don’t use it if the following limitations are a concern:- Collector cannot auto-scale the scraping yet when multiple replicas of the collector are run.
- When running multiple replicas of the collector with the same config, it will scrape the targets multiple times.
- Users need to configure each replica with different scraping configuration if they want to manually shard the scraping.
- The Prometheus receiver is a stateful component.
Unsupported features
The Prometheus receiver is meant to minimally be a drop-in replacement for Prometheus. However, there are advanced features of Prometheus that we don’t support and thus explicitly will return an error for if the receiver’s configuration YAML/code contains any of the following- alert_config.alertmanagers
- alert_config.relabel_configs
- remote_read
- remote_write
- rule_files
Getting Started
This receiver is a drop-in replacement for getting Prometheus to scrape your services. It supports the full set of Prometheus configuration inscrape_config,
including service discovery. Just like you would write in a YAML configuration
file before starting Prometheus, such as with:
Note: Since the collector configuration supports env variable substitution
$ characters in your prometheus configuration are interpreted as environment
variables. If you want to use $ characters in your prometheus configuration,
you must escape them using $$.
config attribute:
- trim_metric_suffixes: [Experimental] When set to true, this enables trimming unit and some counter type suffixes from metric names. For example, it would cause
singing_duration_seconds_totalto be trimmed tosinging_duration. This can be useful when trying to restore the original metric names used in OpenTelemetry instrumentation. Defaults to false.
Complete Configuration Example
The following example demonstrates a complete end-to-end configuration showing how to use the Prometheus receiver with processors and exporters in a service pipeline:- Scrapes metrics from a service running on
localhost:9090every 5 seconds - Filters metrics to keep only those matching
http_request_duration_seconds.*usingmetric_relabel_configs - Adds resource attributes (
deployment.environment) to all metrics (note:service.nameis automatically set from the job name) - Uses exporter-level batching via
sending_queue.batchto improve efficiency when multiple scrapes occur - Exports metrics to both an OTLP endpoint and Prometheus remote write endpoint
Prometheus native histograms
Native histograms are a data type in Prometheus, for more information see the specification. The Prometheus receiver automatically converts native histograms to OpenTelemetry exponential histograms. To enable scraping and ingestion of native histograms, you need to configure two things in your Prometheus scrape config:- Enable native histogram scraping: Set
scrape_native_histograms: true(globally or per-job) - Use the protobuf scrape protocol: Include
PrometheusProtoinscrape_protocols(required until Prometheus supports native histograms over text formats)
always_scrape_classic_histograms.
OpenTelemetry Operator
Additional to this static job definitions this receiver allows to query a list of jobs from the OpenTelemetryOperators TargetAllocator or a compatible endpoint.target_allocator section embeds the full confighttp client configuration.
Exemplars
This receiver accepts exemplars coming in Prometheus format and converts it to OTLP format.- Value is expected to be received in
float64format - Timestamp is expected to be received in
ms - Labels with key
span_idin prometheus exemplars are set as OTLPspan idand labels with keytrace_idare set astrace id - Rest of the labels are copied as it is to OTLP format
Resource and Scope
This receiver drops thetarget_info prometheus metric, if present, and uses attributes on
that metric to populate the OpenTelemetry Resource.
It drops otel_scope_name and otel_scope_version labels, if present, from metrics, and uses them to populate
the OpenTelemetry Instrumentation Scope name and version. It drops the otel_scope_info metric,
and uses attributes (other than otel_scope_name and otel_scope_version) to populate Scope
Attributes.
Prometheus API Server
The Prometheus API server can be enabled to host info about the Prometheus targets, config, service discovery, and metrics. Theserver_config can be specified using the OpenTelemetry confighttp package. An example configuration would be:
- /api/v1/targets
- /api/v1/targets/metadata
- /api/v1/status/config
- /api/v1/scrape_pools
- /metrics
/api/v1/ and the data format that is returned can be found in the Prometheus documentation.
Feature gates
See documentation.md for the complete list of feature gates supported by this receiver. Feature gates can be enabled using the--feature-gates flag:
Benchmark Results
Current Prometheus receiver benchmark results are published on the Collector Benchmarks page. The table below links directly to the current Prometheus receiver charts by scenario and metric type.Troubleshooting and Best Practices
This section provides guidance for common issues, performance optimization, and best practices when using the Prometheus receiver in production environments.Common Issues and Solutions
Metrics Not Appearing
Symptoms: Metrics are not being scraped or exported despite correct configuration. Possible Causes and Solutions:-
Target Not Reachable
- Verify network connectivity between the collector and target endpoints
- Check firewall rules and security groups
- Test connectivity using
curlorwgetto the target’s metrics endpoint
-
Incorrect Scrape Configuration
- Verify
scrape_configssyntax matches Prometheus format - Check that
targetsare correctly formatted (e.g.,['hostname:port']) - Ensure
job_nameis unique and descriptive
- Verify
-
Metric Filtering Too Aggressive
- Review
metric_relabel_configsto ensure desired metrics are not being dropped - Temporarily remove filters to verify metrics are being scraped
- Use the Prometheus API server (if enabled) to inspect active targets
- Review
-
Service Discovery Not Working
- For Kubernetes service discovery, verify RBAC permissions for service account
- Check that service discovery configurations match your environment
- Review collector logs for service discovery errors
/api/v1/targets to see target status and any scrape errors.
- Enable debug logs: You can also enable debug-level logs in the collector to see detailed scrape errors in logs:
High CPU Usage
Symptoms: Collector consuming excessive CPU resources, especially with high metric volumes. Solutions:-
Optimize Scrape Intervals
- Increase
scrape_intervalfor less critical metrics - Use different intervals for different jobs based on metric importance
- Consider using
scrape_timeoutto prevent long-running scrapes
- Increase
-
Reduce Metric Volume
- Use
metric_relabel_configsto drop unnecessary metrics at scrape time - Filter metrics before they enter the pipeline to reduce processing overhead
- Consider using the
filterprocessor for more complex filtering logic
- Use
-
Disable Expensive Features
- Avoid enabling
receiver.prometheusreceiver.EnableCreatedTimestampZeroIngestionunless necessary (known CPU impact) - Use exporter-level batching to reduce export frequency
- Consider disabling extra scrape metrics if not needed
- Avoid enabling
Memory Issues
Symptoms: Collector running out of memory, especially with many targets or long scrape intervals. Solutions:-
Limit Target Count
- Use service discovery filters to reduce number of targets
- Implement manual sharding across multiple collector instances
- Use TargetAllocator for automatic sharding in Kubernetes
-
Optimize Batch Processing
- Configure exporter-level batching with appropriate
send_batch_sizeandtimeoutviasending_queue.batch - Balance between memory usage (smaller batches) and efficiency (larger batches)
- Configure exporter-level batching with appropriate
-
Monitor Memory Usage
- Enable the
memory_limiterprocessor to prevent OOM conditions - Set appropriate memory limits based on your metric volume
- Enable the
Best Practices for Production
Multi-Replica Deployments
When running multiple collector replicas, manually shard scraping to avoid duplicate metrics: Option 1: Manual Sharding by JobPerformance Optimization
-
Scrape Interval Tuning
- Critical metrics: 5-15 seconds
- Standard metrics: 30-60 seconds
- Low-priority metrics: 2-5 minutes
-
Metric Filtering Strategy
- Filter at scrape time using
metric_relabel_configs(most efficient) - Use
filterprocessor for complex logic - Avoid filtering in exporters when possible
- Filter at scrape time using
-
Resource Management
- Always use
memory_limiterprocessor in production - Configure appropriate resource limits in Kubernetes
- Monitor collector metrics (CPU, memory, scrape duration)
- Always use
Monitoring the Receiver
Monitor the Prometheus receiver itself to ensure it’s operating correctly:-
Enable Extra Scrape Metrics
- In the Prometheus config set
extra_scrape_metricstotruein theglobalsection.
- In the Prometheus config set
-
Key Metrics to Monitor:
prometheus_receiver_scrapes_total: Total number of scrapesprometheus_receiver_scrape_errors_total: Number of failed scrapesprometheus_receiver_target_scrapes_exceeded_timeout_total: Timeouts- Collector’s internal metrics (CPU, memory, pipeline metrics)
-
Set Up Alerts:
- Alert on high scrape error rates
- Alert on scrape timeouts
- Alert on collector memory/CPU usage
Security Considerations
-
TLS Configuration
- Always use TLS for exporter endpoints in production
- Use proper certificate management
- Consider using mTLS for enhanced security
-
Network Security
- Restrict network access to metrics endpoints
- Use service meshes or network policies to limit exposure
- Consider using authentication for sensitive metrics endpoints
-
Configuration Security
- Avoid hardcoding credentials in configuration files
- Use environment variable substitution for sensitive values
- Implement proper secret management (e.g., Kubernetes secrets)
Debugging Tips
-
Enable Verbose Logging
-
Use Prometheus API Server
- Enable API server to inspect targets, config, and scrape pools
- Query
/api/v1/targetsto see target health - Check
/api/v1/status/configto verify configuration
-
Test Configuration
- Validate YAML syntax before deployment
- Test with a single job first, then expand
- Use
otelcolwith--dry-runflag if available
-
Check Collector Logs
- Look for scrape errors, timeouts, or connection issues
- Monitor for memory or CPU warnings
- Review service discovery logs for Kubernetes deployments
Additional Resources
- Prometheus Configuration Documentation
- OpenTelemetry Collector Documentation
- Design Document for implementation details
Configuration
config.yaml (testdata)
config.yaml (testdata)
Last generated: 2026-04-13