Skip to content

fix: raise ValueError for unsorted ExplicitBucketHistogramAggregation boundaries#5340

Open
RudraDudhat2509 wants to merge 4 commits into
open-telemetry:mainfrom
RudraDudhat2509:fix/explicit-bucket-histogram-unsorted-boundaries
Open

fix: raise ValueError for unsorted ExplicitBucketHistogramAggregation boundaries#5340
RudraDudhat2509 wants to merge 4 commits into
open-telemetry:mainfrom
RudraDudhat2509:fix/explicit-bucket-histogram-unsorted-boundaries

Conversation

@RudraDudhat2509

@RudraDudhat2509 RudraDudhat2509 commented Jun 22, 2026

Copy link
Copy Markdown

Fixes #5338

What's wrong

ExplicitBucketHistogramAggregation accepts unsorted boundary lists without any validation. bisect_left (used in aggregate()) requires sorted input with unsorted boundaries, measurements are silently placed in the wrong buckets with no error or warning.

What this does

Adds a validation loop in _ExplicitBucketHistogramAggregation.__init__ that raises ValueError if boundaries are not strictly increasing. This matches the behavior of the Java SDK (IllegalArgumentException) and the Go SDK (non-monotonic boundaries error).

Tests

Added test_unsorted_boundaries_raise and test_duplicate_boundaries_raise to TestExplicitBucketHistogramAggregation.

@RudraDudhat2509 RudraDudhat2509 requested a review from a team as a code owner June 22, 2026 13:52
@RudraDudhat2509

Copy link
Copy Markdown
Author
image

tests pass on local

instrument_aggregation_temporality
)
self._start_time_unix_nano = start_time_unix_nano
for i in range(1, len(boundaries)):

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.

Java also checks that first and last elements are not -inf and +inf, I guess it won't hurt

@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest Jun 22, 2026
@RudraDudhat2509

RudraDudhat2509 commented Jun 22, 2026

Copy link
Copy Markdown
Author

good call added finite checks for NaN, +inf, and -inf, matching Java's full validation. tests added for all three cases

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

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

ExplicitBucketHistogramAggregation silently accepts unsorted boundaries, producing wrong bucket assignments

2 participants