Skip to content

Commit

Permalink
Fix delta histogram sum not being reset on collection (#2533)
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Mar 21, 2022
1 parent 09a03ae commit f7b33c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2525](https://github.com/open-telemetry/opentelemetry-python/pull/2525))
- Change OTLPHandler to LoggingHandler
([#2528](https://github.com/open-telemetry/opentelemetry-python/pull/2528))
- Fix delta histogram sum not being reset on collection
([#2533](https://github.com/open-telemetry/opentelemetry-python/pull/2533))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,19 @@ def collect(self) -> Histogram:
with self._lock:
value = self._bucket_counts
start_time_unix_nano = self._start_time_unix_nano
histogram_sum = self._sum

self._bucket_counts = self._get_empty_bucket_counts()
self._start_time_unix_nano = now + 1
self._sum = 0

return Histogram(
start_time_unix_nano=start_time_unix_nano,
time_unix_nano=now,
bucket_counts=tuple(value),
explicit_bounds=self._boundaries,
aggregation_temporality=AggregationTemporality.DELTA,
sum=self._sum,
sum=histogram_sum,
)


Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def test_collect(self):
first_histogram = explicit_bucket_histogram_aggregation.collect()

self.assertEqual(first_histogram.bucket_counts, (0, 1, 0, 0))
self.assertEqual(first_histogram.sum, 1)

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

self.assertEqual(second_histogram.bucket_counts, (0, 1, 0, 0))
self.assertEqual(second_histogram.sum, 1)

self.assertGreater(
second_histogram.time_unix_nano, first_histogram.time_unix_nano
Expand Down

0 comments on commit f7b33c6

Please sign in to comment.