Repository navigation
fix(otlp): put downscaled exponential histogram counts in the right buckets - #20079
Merged
Merged
Conversation
…uckets When an OTel exponential histogram with scale above 8 was downscaled and a merged bucket summed to zero, the next merged bucket built from two or more input buckets was split across the wrong output buckets. The empty bucket branch in convertBucketsLayout did not advance bucketIdx, so the next input bucket of the same group was treated as the start of a new group. The total count was unaffected, so validation did not catch it. Track the index of the last appended bucket separately and compute gaps from it, so empty merged buckets are skipped without losing position. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: György Krajcsovits <[email protected]>
krajorama
requested review from
a team,
ArthurSens,
aknuds1 and
jesusvazquez
as code owners
October 19, 2026 16:41
Member
Author
|
Found while reviewing open-telemetry/opentelemetry-collector-contrib#51735 |
aknuds1
approved these changes
Oct 20, 2026
ArthurSens
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the OTLP endpoint receives an exponential histogram with a scale above 8, it downscales it to schema 8 by merging neighbouring buckets. If a merged bucket added up to zero, the next merged bucket built from two or more input buckets was split across the wrong output buckets. Examples (offset 0, one level of downscaling):
[0,0,5,3][1,0,0,0,5,3]The
count == 0branch inconvertBucketsLayoutdid not advancebucketIdx, so the next input bucket in the same group was treated as the start of a new group. The total count stayed correct, so validation didn't catch it and the data was silently wrong. OTel SDKs default to a max scale of 20, so downscaling is common. Without downscaling, the gap calculation made up for the stale index, so those results were correct. The bug has been there since the OTLP endpoint was added.The fix keeps the index of the last appended bucket in a separate variable and computes gaps from it, so empty merged buckets can be skipped without losing track of position. A randomized comparison (500k inputs, scale-down 0–3, both
adjustOffsetmodes, not committed) checked that every bucket now lands where it should. It also checked that the spans and deltas are byte-for-byte the same as before for every input the old code got right, which covers all cases without downscaling.BenchmarkConvertBucketLayoutshows no significant change.The same code exists in
opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite.🤖 Generated with Claude Code