Skip to content

Commit f7b33c6

Browse files
authored
Fix delta histogram sum not being reset on collection (#2533)
1 parent 09a03ae commit f7b33c6

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
([#2525](https://github.com/open-telemetry/opentelemetry-python/pull/2525))
1313
- Change OTLPHandler to LoggingHandler
1414
([#2528](https://github.com/open-telemetry/opentelemetry-python/pull/2528))
15+
- Fix delta histogram sum not being reset on collection
16+
([#2533](https://github.com/open-telemetry/opentelemetry-python/pull/2533))
1517

1618
## [1.10.0-0.29b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.10.0-0.29b0) - 2022-03-10
1719

opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,19 @@ def collect(self) -> Histogram:
191191
with self._lock:
192192
value = self._bucket_counts
193193
start_time_unix_nano = self._start_time_unix_nano
194+
histogram_sum = self._sum
194195

195196
self._bucket_counts = self._get_empty_bucket_counts()
196197
self._start_time_unix_nano = now + 1
198+
self._sum = 0
197199

198200
return Histogram(
199201
start_time_unix_nano=start_time_unix_nano,
200202
time_unix_nano=now,
201203
bucket_counts=tuple(value),
202204
explicit_bounds=self._boundaries,
203205
aggregation_temporality=AggregationTemporality.DELTA,
204-
sum=self._sum,
206+
sum=histogram_sum,
205207
)
206208

207209

opentelemetry-sdk/tests/metrics/test_aggregation.py

+2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def test_collect(self):
286286
first_histogram = explicit_bucket_histogram_aggregation.collect()
287287

288288
self.assertEqual(first_histogram.bucket_counts, (0, 1, 0, 0))
289+
self.assertEqual(first_histogram.sum, 1)
289290

290291
# CI fails the last assertion without this
291292
sleep(0.1)
@@ -294,6 +295,7 @@ def test_collect(self):
294295
second_histogram = explicit_bucket_histogram_aggregation.collect()
295296

296297
self.assertEqual(second_histogram.bucket_counts, (0, 1, 0, 0))
298+
self.assertEqual(second_histogram.sum, 1)
297299

298300
self.assertGreater(
299301
second_histogram.time_unix_nano, first_histogram.time_unix_nano

0 commit comments

Comments
 (0)