Skip to content

fix(sdk): validate ExplicitBucketHistogramAggregation boundaries early - #5960

Closed
gathre wants to merge 1 commit into
open-telemetry:mainfrom
gathre:fix/validate-histogram-aggregation-boundaries
Closed

gathre wants to merge 1 commit into
open-telemetry:mainfrom
gathre:fix/validate-histogram-aggregation-boundaries

Conversation

@gathre

@gathre gathre commented Nov 24, 2026

Copy link
Copy Markdown

Which problem is this PR solving?

Fixes #5951

When configuring an ExplicitBucketHistogramAggregation in a View with invalid boundaries (such as unsorted numbers [100.0, 10.0, 50.0], duplicate numbers [1.0, 1.0], or non-finite values [float("nan")]), ExplicitBucketHistogramAggregation.__init__ accepted the boundaries without validation. The validation was deferred to internal _ExplicitBucketHistogramAggregation.__init__ during measurement recording (histogram.record(...)), raising an uncaught ValueError: boundaries must be strictly increasing and crashing host applications at runtime.

Per the OpenTelemetry Error Handling Specification:

"OpenTelemetry implementations MUST NOT throw unhandled exceptions at runtime."

Short description of the changes

  1. Early Validation: Added _validate_boundaries to ExplicitBucketHistogramAggregation.__init__ so invalid boundaries are caught and rejected immediately at instantiation time.
  2. Safe Advisory Fallback: In _explicit_bucket_boundaries_from_advisory, validate advised boundaries before returning them; if invalid, log a warning and fall back to default boundaries (_DEFAULT_EXPLICIT_BUCKET_HISTOGRAM_AGGREGATION_BOUNDARIES) so runtime operations never crash.
  3. Tests:
    • Added unit tests in tests/metrics/test_aggregation.py verifying that invalid boundaries passed to ExplicitBucketHistogramAggregation raise ValueError.
    • Added unit test in tests/metrics/integration_test/test_histogram_advisory_explicit_buckets.py verifying that invalid boundaries from an instrument advisory safely fall back to default boundaries with a logged warning.

Type of change

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

Validate explicit bucket boundaries early at initialization time in ExplicitBucketHistogramAggregation instead of deferring to runtime measurement collection. If advised boundaries on an instrument are invalid, safely log a warning and fall back to default boundaries.

Fixes open-telemetry#5951
@gathre
gathre requested a review from a team as a code owner November 24, 2026 11:21
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@opentelemetry-pr-dashboard

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

Copy link
Copy Markdown

Pull request dashboard status

Closed · refreshed 2026-11-25 18:14 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

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.

ExplicitBucketHistogramAggregation with unsorted or invalid boundaries crashes histogram.record() with uncaught ValueError

2 participants