fix(metrics): guard _advisory access in ExplicitBucketHistogramAggregation for non-Histogram instruments#5034
Merged
xrmx merged 3 commits intoopen-telemetry:mainfrom Apr 3, 2026
Conversation
33fdf5c to
7fe993c
Compare
xrmx
reviewed
Apr 2, 2026
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py
Show resolved
Hide resolved
7fe993c to
bd9e33c
Compare
xrmx
approved these changes
Apr 2, 2026
Contributor
xrmx
left a comment
There was a problem hiding this comment.
Thanks for investigating this!
…ation for non-Histogram instruments
bd9e33c to
c29e93e
Compare
emdneto
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ExplicitBucketHistogramAggregation._create_aggregation()unconditionally accessesinstrument._advisory.explicit_bucket_boundarieswhen no explicit boundaries are provided. The_advisoryattribute only exists onHistograminstruments — when this aggregation is applied to other instrument types (e.g.Counter) viapreferred_aggregation, it raisesAttributeError.This became reachable in practice after
TracerMetrics(added in 1.40.0) began registeringCounterandUpDownCounterinstruments through the globalMeterProvider.The fix uses a safe
getattrguard, falling back toNoneboundaries when_advisoryis absent.Type of change
How Has This Been Tested?
test_explicit_bucket_histogram_on_instrument_without_boundaries— appliesExplicitBucketHistogramAggregation()(no boundaries) to a_Counterinstrument and asserts it produces a valid_ExplicitBucketHistogramAggregationinstead of crashingDoes This PR Require a Contrib Repo Change?
Checklist:
Red/green tests: