Skip to content

opentelemetry-exporter-prometheus: add support to configure Resource attributes as metric labels#5122

Open
herin049 wants to merge 4 commits into
open-telemetry:mainfrom
herin049:feat/prometheus-resource-attrs
Open

opentelemetry-exporter-prometheus: add support to configure Resource attributes as metric labels#5122
herin049 wants to merge 4 commits into
open-telemetry:mainfrom
herin049:feat/prometheus-resource-attrs

Conversation

@herin049

@herin049 herin049 commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

uv run tox -e py314-test-opentelemetry-exporter-prometheus

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@herin049 herin049 requested a review from a team as a code owner April 18, 2026 02:33
@herin049 herin049 added Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary exporters labels Apr 18, 2026

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@MikeGoldsmith MikeGoldsmith moved this to Approved PRs in Python PR digest Apr 21, 2026
@herin049 herin049 force-pushed the feat/prometheus-resource-attrs branch 2 times, most recently from 2befd3e to f2eeff0 Compare April 29, 2026 21:21
@herin049 herin049 force-pushed the feat/prometheus-resource-attrs branch from 784aa8a to ad17d8b Compare May 14, 2026 01:30
@github-actions

Copy link
Copy Markdown

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.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label May 28, 2026
@herin049 herin049 removed the Stale label Jun 5, 2026
@herin049 herin049 force-pushed the feat/prometheus-resource-attrs branch from aa62ad2 to 8ecb28d Compare June 17, 2026 02:54
@herin049 herin049 changed the title feat: add support for Resource attributes configuration for Prometheus exporter opentelemetry-exporter-prometheus: add support to configure Resource attributes as metric labels Jun 17, 2026
@herin049 herin049 requested review from aabmass and Copilot June 17, 2026 02:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_filter callback on PrometheusMetricReader to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary exporters

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

Stabilize Prometheus Exporter: Resource Attributes

4 participants