Skip to content

fix(metrics): reset the exponent mapping between DELTA collections - #5717

Closed
inchang-ing wants to merge 12 commits into
open-telemetry:mainfrom
inchang-ing:fix-5716-delta-scale-reset
Closed

inchang-ing wants to merge 12 commits into
open-telemetry:mainfrom
inchang-ing:fix-5716-delta-scale-reset

Conversation

@inchang-ing

Copy link
Copy Markdown

Description

Fixes #5716.

With DELTA temporality, the exponential histogram aggregation lowered its scale when an interval's values spanned a wide range but never raised it again: collect reset the buckets and _scale but not the exponent mapping. Every later delta point was therefore recorded — and reported — at the lowest scale any earlier interval needed, even when it held a single value.

The spec says that when either range holds not more than one value, the scale SHOULD be the maximum; a delta point covers only its own interval, so the mapping must not leak across collections.

Fix

In the DELTA→DELTA branch of _ExponentialBucketHistogramAggregation.collect, reset self._mapping to the maximum scale after the interval is captured. The next interval starts fresh and downscales again as needed. The CUMULATIVE branch is untouched (a cumulative point legitimately spans its whole lifetime, so its mapping keeps lowering).

Validation

  • New regression tests (opentelemetry-sdk/tests/metrics/exponential_histogram/test_delta_scale_reset.py), mirroring the issue's reproduction with InMemoryMetricReader:
    • a wide interval downscales (scale 2) and the following single-value intervals return to the maximum scale (20) — fails on main, where they stay pinned at 2;
    • repeated wide intervals still downscale every time.
  • Full existing suite for the aggregation class (test_exponential_bucket_histogram_aggregation.py: 22 tests + 5 subtests) passes with the change; CUMULATIVE temporality behavior verified unchanged.

@inchang-ing
inchang-ing requested a review from a team as a code owner September 30, 2026 19:27
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Closed · refreshed 2026-10-29 03:39 UTC

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

…etry#5716)

Match the unittest-style assertions used by the other exponential histogram tests and add the .changelog fragment required by CI.
@inchang-ing

Copy link
Copy Markdown
Author

Done in 1a6912a — switched to unittest-style self.assertEqual and added the .changelog/5717.fixed fragment.

@inchang-ing

Copy link
Copy Markdown
Author

Hi maintainers, gentle ping on #5717 — fix(metrics): reset the exponent mapping between DELTA collections. It's a small, self-contained fix with passing tests. Would appreciate a review when you have a moment. Thanks for maintaining open-telemetry/opentelemetry-python!

… add exhaustive tests

- Move the mapping reset to the top of the DELTA/DELTA branch of collect(),
  grouped with the delta bookkeeping instead of sitting between the empty
  check and the data point construction. It stays under the lock because
  aggregate() reads and rewrites self._mapping under the same lock, and it
  stays inside the delta branch because a cumulative collection needs the
  mapping to survive across collections.
- Make the regression tests more exhaustive: the reset now also survives an
  interval without records, happens on every collection (alternating wide and
  narrow intervals), and buckets values with the maximum-scale mapping (the
  reported bucket offset matches LogarithmMapping(20)).
@github-project-automation github-project-automation Bot moved this from Ready for review to Approved PRs in Python PR digest Oct 12, 2026
@herin049
herin049 requested a balanced review from Copilot October 14, 2026 18:38

Copilot AI left a comment

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.

🟢 Approval recommended

The isolated fix has targeted regression coverage and no unresolved review findings.

0 open findings

What changed in this PR

Fixes #5716 by allowing DELTA exponential histograms to regain precision after a wide-range interval.

Changes:

  • Resets the exponent mapping between DELTA collections without changing cumulative behavior.
  • Adds regression tests for scale recovery and repeated downscaling.
  • Adds a changelog entry.
File Description
opentelemetry-sdk/​tests/​metrics/​exponential_histogram/​test_delta_scale_reset.py Tests scale recovery and repeated downscaling.
opentelemetry-sdk/​src/​opentelemetry/​sdk/​metrics/​_internal/​aggregation.py Resets the mapping after capturing a DELTA interval.
.changelog/​5717.fixed Documents the fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@herin049 herin049 closed this Oct 29, 2026
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Oct 29, 2026
@herin049

Copy link
Copy Markdown
Contributor

Thanks for your contribution efforts. Unfortunately it looks like the changes are now redundant from #5809.

@inchang-ing

Copy link
Copy Markdown
Author

Thanks — agreed, #5809 supersedes this now that it enforces the cardinality limits upstream. Closing. If any part of the exponent-mapping reset is still missing from the merged version, point me at it and I will reopen with just that piece.

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.

Delta exponential histogram never goes back to the maximum scale after a wide-range interval

4 participants