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).

ocelotl added 2 commits July 1, 2026 14:02
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