Skip to content

exporter/prometheus: Add config option 'resource_constant_labels'#48922

Open
ArthurSens wants to merge 9 commits into
open-telemetry:mainfrom
ArthurSens:promexporter-resourceconstlabels
Open

exporter/prometheus: Add config option 'resource_constant_labels'#48922
ArthurSens wants to merge 9 commits into
open-telemetry:mainfrom
ArthurSens:promexporter-resourceconstlabels

Conversation

@ArthurSens

@ArthurSens ArthurSens commented Jun 8, 2026

Copy link
Copy Markdown
Member

Description

Adds the config option resource_constant_labels with two arrays include and exclude, to select which resource attributes are translated to labels during exposition.

The new config is hidden behind a feature gate that, once enabled, will also disable the deprecated config option resource_to_telemetry_conversion, which uses an "all or nothing" approach.

Link to tracking issue

Fixes #48861

Authorship

  • I, a human, wrote this pull request description myself.
  • AI wrote the code though :)

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

Adds a new Prometheus exporter configuration option to selectively copy resource attributes into metric labels, aligning better with Prometheus/Otel recommendations while keeping backward compatibility via a feature gate.

Changes:

  • Introduces resource_constant_labels (with included/excluded) behind the exporter.prometheusexporter.ResourceConstantLabels feature gate and disables the legacy resource_to_telemetry_conversion when the gate is enabled.
  • Adds config unmarshalling + validation to enforce mutual exclusivity and feature-gate requirements.
  • Updates metric label construction to optionally upsert selected resource attributes into metric labelsets; adds tests and documentation updates.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
exporter/prometheusexporter/testdata/config.yaml Adds test config coverage for the new and legacy configuration blocks.
exporter/prometheusexporter/README.md Documents resource_constant_labels, deprecates resource_to_telemetry_conversion, and updates usage guidance/examples.
exporter/prometheusexporter/prometheus_test.go Adds an end-to-end scrape test validating resource attribute copying behavior under the feature gate.
exporter/prometheusexporter/metadata.yaml Registers the new feature gate metadata for mdatagen/docs.
exporter/prometheusexporter/internal/metadata/generated_feature_gates.go Adds generated Go registration for the new feature gate.
exporter/prometheusexporter/factory.go Validates config early and conditionally applies the legacy resource-to-telemetry wrapper based on the feature gate.
exporter/prometheusexporter/documentation.md Lists the new feature gate in the autogenerated docs table.
exporter/prometheusexporter/config.schema.yaml Extends the config schema with the optional resource_constant_labels object and deprecation note.
exporter/prometheusexporter/config.go Adds ResourceConstantLabels, custom Unmarshal tracking for legacy presence, and feature-gate/mutual-exclusion validation.
exporter/prometheusexporter/config_test.go Extends config loading tests and adds validation tests around the feature gate behavior.
exporter/prometheusexporter/collector.go Adds optional copying of selected resource attributes into metric labels (with collision-safe upsert behavior).
exporter/prometheusexporter/collector_test.go Adds a focused unit test asserting include/exclude behavior and precedence when keys overlap.
Files not reviewed (1)
  • exporter/prometheusexporter/internal/metadata/generated_feature_gates.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread exporter/prometheusexporter/collector.go Outdated

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

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • exporter/prometheusexporter/internal/metadata/generated_feature_gates.go: Language not supported

Comment thread exporter/prometheusexporter/factory.go Outdated
songy23 pushed a commit that referenced this pull request Jun 8, 2026
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

While working on #48922, CI complained about broken links.

Looks like the old page got moved by
prometheus/docs#2656

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens
ArthurSens force-pushed the promexporter-resourceconstlabels branch from 89cac4d to c813473 Compare June 8, 2026 17:41
from_version: "v0.132.0"
reference_url: https://github.com/open-telemetry/opentelemetry-specification/pull/4533
skip_strict_validation: true
- id: exporter.prometheusexporter.ResourceConstantLabels

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.

I usually prefer just having the feature gate guard the deprecation of the old thing, and not prevent people from using the new thing. I.e. just make this exporter.prometheusexporter.RemoveResourceToTelemetry

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens

ArthurSens commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

Let's put this PR on hold until open-telemetry/opentelemetry-specification#5130 is sorted out

@github-actions

Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Jul 10, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 18, 2026

Copy link
Copy Markdown

Pull request dashboard status

Status last refreshed: 2026-07-24 15:35:18 UTC.

  • Waiting on: Reviewers
  • Next step: Review the latest changes.

This automated status or its linked feedback items may be incorrect. If something looks wrong, please report it with the result you expected.

bruegth pushed a commit to bruegth/opentelemetry-collector-contrib that referenced this pull request Jul 22, 2026
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

While working on open-telemetry#48922, CI complained about broken links.

Looks like the old page got moved by
prometheus/docs#2656

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@github-actions github-actions Bot removed the Stale label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[exporter/prometheus] Implement configuration option: resource_constant_labels

4 participants