Skip to content

Do not promote resource attributes for empty resource_constant_labels - #9048

Open
samirsahoo wants to merge 1 commit into
open-telemetry:mainfrom
samirsahoo:fix/prometheus-empty-resource-constant-labels
Open

samirsahoo wants to merge 1 commit into
open-telemetry:mainfrom
samirsahoo:fix/prometheus-empty-resource-constant-labels

Conversation

@samirsahoo

Copy link
Copy Markdown

Fixes #9014

Problem

An empty resource_constant_labels: {} mapping is valid against the opentelemetry-configuration JSON Schema, and parses into a non-null DeclarativeConfigProperties whose included and excluded are both null. PrometheusComponentProvider passed both to IncludeExcludePredicate.createPatternMatching(null, null), which returns an include-all predicate (attributeKey -> true). The result is that every resource attribute was added as a label on every exported metric series:

meter_provider:
  readers:
    - pull:
        exporter:
          prometheus/development:
            resource_constant_labels: {}

Fix

Only set the filter when at least one of included / excluded is configured. When neither is, the filter stays unset, which is the default of no resource attributes as metric labels.

This matches the prometheus exporter specification ("By default, it MUST NOT add any resource attributes as metric labels"), the documented defaultBehavior of ExperimentalPrometheusMetricExporter.resource_constant_labels, and the Collector's pkg/resourcetotelemetry IsEmpty() check.

The existing validation that rejects an explicitly empty included: [] or excluded: [] list is unchanged.

Tests

Adds PrometheusComponentProviderTest covering resource_constant_labels absent, empty ({}), included, excluded, and the two empty-list rejections. Reverting the one-line guard fails exactly the empty-mapping case.

An empty `resource_constant_labels: {}` mapping in declarative configuration
leaves both `included` and `excluded` null. `PrometheusComponentProvider`
passed both to `IncludeExcludePredicate.createPatternMatching`, which returns
an include-all predicate, so every resource attribute was added as a label on
every exported metric series.

The prometheus exporter specification requires that no resource attributes are
added as metric labels by default, so leave the filter unset when neither
`included` nor `excluded` is configured.

Fixes open-telemetry#9014
@samirsahoo
samirsahoo requested a review from a team as a code owner November 21, 2026 15:37
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: samirsahoo / name: Samir (6019c65)

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-23 02:27 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (f0549eb) to head (6019c65).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9048   +/-   ##
=========================================
  Coverage     90.45%   90.46%           
- Complexity    11182    11188    +6     
=========================================
  Files          1032     1032           
  Lines         30508    30509    +1     
  Branches       3992     3993    +1     
=========================================
+ Hits          27596    27599    +3     
+ Misses         1935     1934    -1     
+ Partials        977      976    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samirsahoo

Copy link
Copy Markdown
Author

Signed the EasyCLA

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PrometheusComponentProvider promotes all resource attributes when resource_constant_labels is empty ({})

1 participant