Skip to content

fix(sdk): correctly merge exponential histogram buckets that start empty - #5378

Draft
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:issue_3219
Draft

fix(sdk): correctly merge exponential histogram buckets that start empty#5378
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:issue_3219

Conversation

@ocelotl

@ocelotl ocelotl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds the test requested by Enhance exponential histogram tests #3219: verify that merging two exponential histograms (via cumulative collection across two windows) produces the same result as aggregating all values in a single pass.
  • Writing that test uncovered a real bug in _ExponentialBucketHistogramAggregation._merge: when one side of the histogram (positive or negative buckets) has never received a value, its placeholder index_start/index_end (0) was treated as a real boundary during merge, which could corrupt bucket offsets or raise a spurious Incorrect merge scale exception. Fixed by initializing the empty side from the first incoming index, mirroring the existing logic in aggregate().

Fixes #3219

Test plan

  • Added test_merge_into_empty_buckets: minimal deterministic repro of the bug.
  • Added test_merging_two_histograms_equals_aggregating_independently: randomized property test comparing split-and-merge vs. single-pass aggregation.
  • Verified both new tests fail against the pre-fix code and pass with the fix.
  • Full opentelemetry-sdk metrics test suite passes (296 tests).

@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-08-20 16:49 UTC

Move out of draft to request review.

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.

Add a test verifying that merging two exponential histograms across
cumulative collections produces the same result as aggregating all
values in one pass, per issue open-telemetry#3219. This uncovered a bug: when one
side (positive or negative) of the histogram has never received a
value, its placeholder index_start/index_end (0) was treated as a
real boundary during merge, corrupting or crashing the merge instead
of being initialized from the first incoming value.
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.

Enhance exponential histogram tests

1 participant