opentelemetry-exporter-prometheus: add support to configure Resource attributes as metric labels#5122
Conversation
2befd3e to
f2eeff0
Compare
784aa8a to
ad17d8b
Compare
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
aa62ad2 to
8ecb28d
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a configuration hook to the Prometheus exporter that allows selected OpenTelemetry Resource attributes to be copied onto exported Prometheus metrics as labels, aligning the Python Prometheus exporter with the Prometheus compatibility guidance in the OpenTelemetry specification.
Changes:
- Introduces a
resource_attr_filtercallback onPrometheusMetricReaderto select which Resource attributes should become metric labels (sanitized to valid Prometheus label names). - Updates label construction so copied Resource labels are included on exported samples, while preserving precedence (metric point attributes override copied Resource attributes).
- Adds unit tests and documentation describing the new configuration, plus a changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/init.py | Adds resource_attr_filter wiring and includes filtered Resource attributes in label generation. |
| exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py | Adds tests covering default behavior, filtering, sanitization, and precedence with point/scope labels. |
| docs/exporter/prometheus/prometheus.rst | Documents how to enable Resource attributes as metric labels via resource_attr_filter. |
| .changelog/5122.added | Records the new Prometheus exporter feature in the changelog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Adds support for adding Resource attributes as metric labels for the Prometheus exporter in accordance to the Prometheus spec.
Fixes #5110
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: