Skip to content

fix(metrics): guard _advisory access in ExplicitBucketHistogramAggregation for non-Histogram instruments#5034

Merged
xrmx merged 3 commits intoopen-telemetry:mainfrom
giorgiovilardo:fix/explicit-bucket-histogram-advisory-guard
Apr 3, 2026
Merged

fix(metrics): guard _advisory access in ExplicitBucketHistogramAggregation for non-Histogram instruments#5034
xrmx merged 3 commits intoopen-telemetry:mainfrom
giorgiovilardo:fix/explicit-bucket-histogram-advisory-guard

Conversation

@giorgiovilardo
Copy link
Copy Markdown
Contributor

Description

ExplicitBucketHistogramAggregation._create_aggregation() unconditionally accesses instrument._advisory.explicit_bucket_boundaries when no explicit boundaries are provided. The _advisory attribute only exists on Histogram instruments — when this aggregation is applied to other instrument types (e.g. Counter) via preferred_aggregation, it raises AttributeError.

This became reachable in practice after TracerMetrics (added in 1.40.0) began registering Counter and UpDownCounter instruments through the global MeterProvider.

The fix uses a safe getattr guard, falling back to None boundaries when _advisory is absent.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • test_explicit_bucket_histogram_on_instrument_without_boundaries — applies ExplicitBucketHistogramAggregation() (no boundaries) to a _Counter instrument and asserts it produces a valid _ExplicitBucketHistogramAggregation instead of crashing

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

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

Red/green tests:

image image image

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 2, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: giorgiovilardo / name: Giorgio Vilardo (5e58552, c29e93e)
  • ✅ login: xrmx / name: Riccardo Magliocchetti (8e3ff20)

@giorgiovilardo giorgiovilardo force-pushed the fix/explicit-bucket-histogram-advisory-guard branch 2 times, most recently from 33fdf5c to 7fe993c Compare April 2, 2026 10:39
@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest Apr 2, 2026
@giorgiovilardo giorgiovilardo force-pushed the fix/explicit-bucket-histogram-advisory-guard branch from 7fe993c to bd9e33c Compare April 2, 2026 10:44
Copy link
Copy Markdown
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

Thanks for investigating this!

@giorgiovilardo giorgiovilardo force-pushed the fix/explicit-bucket-histogram-advisory-guard branch from bd9e33c to c29e93e Compare April 2, 2026 10:53
@xrmx xrmx moved this from Reviewed PRs that need fixes to Approved PRs in Python PR digest Apr 2, 2026
@xrmx xrmx enabled auto-merge (squash) April 3, 2026 08:33
@xrmx xrmx merged commit 1d6171b into open-telemetry:main Apr 3, 2026
508 checks passed
@github-project-automation github-project-automation bot moved this from Approved PRs to Done in Python PR digest Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants