Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#5,716 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@inchang-ing 已经在做这个了。

开始于 2026年9月30日。

  • #5717 来自 @inchang-ing —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
observability

调研方向

从 opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py 中的 _ExponentialBucketHistogramAggregation.collect 及其 DELTA→DELTA 分支开始。使用提供的脚本重现该问题,然后检查 metrics 测试以找到合适的回归测试位置。完成的标准是,后续的单值 delta 区间能够恢复到最大 scale,同时不破坏现有的 metrics 测试套件。

由索引模型根据 Issue 内容生成。

描述

Describe your environment

OS: macOS (arm64)
Python version: 3.12
SDK version: main at 18d7e24 (opentelemetry-sdk installed from source)
API version: main at 18d7e24

What happened?

With DELTA temporality, the exponential histogram aggregation lowers its scale when an interval's values span a wide range, but never raises it again. Collection resets the buckets but not self._mapping (_ExponentialBucketHistogramAggregation.collect, the DELTA→DELTA branch in opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py). So every later delta point keeps the lowest scale any earlier interval needed, even when it holds a single value.

The SDK spec says: "When the histogram contains not more than one value in either of the positive or negative ranges, the implementation SHOULD use the maximum scale." A delta point covers only its own interval.

Steps to Reproduce
from opentelemetry.sdk.metrics import Histogram, MeterProvider
from opentelemetry.sdk.metrics.export import AggregationTemporality, InMemoryMetricReader
from opentelemetry.sdk.metrics.view import ExponentialBucketHistogramAggregation, View

reader = InMemoryMetricReader(preferred_temporality={Histogram: AggregationTemporality.DELTA})
provider = MeterProvider(
    metric_readers=[reader],
    views=[View(instrument_name="latency", aggregation=ExponentialBucketHistogramAggregation())],
)
hist = provider.get_meter("demo").create_histogram("latency")


def point():
    return reader.get_metrics_data().resource_metrics[0].scope_metrics[0].metrics[0].data.data_points[0]


hist.record(1e-6)
hist.record(1e6)
print(point().scale)  # interval 1: 2

for _ in range(3):
    hist.record(5.0)
    print(point().scale)  # each later interval holds one value: 2, 2, 2
Expected Result

Each interval after the first holds a single value, so it's exported at the maximum scale (20 by default), with positive.offset = 2434718.

Actual Result

Every later interval is exported at scale 2, with positive.offset = 9. That bucket is (4.757, 5.657], a relative error of about 8.6% instead of about 3.3e-7 at scale 20. It never recovers.

In a worse case, one interval that records 1e-300 and 1e300 pins later intervals at scale -4. After that, four measurements of 10, 12, 15 and 20 ms all land in the single bucket (2^-16, 1].

Additional context

Adding self._mapping = self._new_mapping(self._max_scale) in that DELTA→DELTA branch, next to the bucket reset, restores the maximum scale for every interval. With it, the reproduction above prints 20 for each later interval, and the outlier case goes back to scale 7 with the four values in separate buckets. The 335 tests in opentelemetry-sdk/tests/metrics pass with and without the change, so none of them currently covers this.

For comparison, jmacd noted during review of #2964 that when the structure goes from 0 measurements to 1, "the scale is supposed to reset to the maximum scale again".

Found while auditing the metrics SDK with Claude Code. The outputs above come from running the script against main at 18d7e24.

Would you like to implement a fix?

Not at the moment. The one-line change above is what I tested, and anyone is welcome to pick it up.

主要语言
Python
星标
2.7k
派生
1k
平均合并
3 天 5 小时
30 天内合并 PR
45

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

open-telemetry/opentelemetry-python 的其他 Issue

查看 open-telemetry/opentelemetry-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。