From 57a3b17c7085c2db38155948f86a63ab4d8536f0 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 2 Feb 2022 10:17:27 -0800 Subject: [PATCH] [metrics] add sum attribute to Histogram (#2431) --- .../src/opentelemetry/sdk/_metrics/aggregation.py | 1 + opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py | 1 + opentelemetry-sdk/tests/metrics/test_aggregation.py | 3 +++ 3 files changed, 5 insertions(+) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py index 18b43d7f725..5048d146b49 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py @@ -198,4 +198,5 @@ def collect(self) -> Optional[Histogram]: bucket_counts=tuple(value), explicit_bounds=self._boundaries, aggregation_temporality=AggregationTemporality.DELTA, + sum=self._sum, ) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py index bd69257b938..1586beb4d73 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/point.py @@ -48,6 +48,7 @@ class Histogram: time_unix_nano: int bucket_counts: Sequence[int] explicit_bounds: Sequence[float] + sum: Union[int, float] aggregation_temporality: AggregationTemporality diff --git a/opentelemetry-sdk/tests/metrics/test_aggregation.py b/opentelemetry-sdk/tests/metrics/test_aggregation.py index 6ca443e7a98..535d8d44d56 100644 --- a/opentelemetry-sdk/tests/metrics/test_aggregation.py +++ b/opentelemetry-sdk/tests/metrics/test_aggregation.py @@ -251,6 +251,9 @@ def test_aggregate(self): explicit_bucket_histogram_aggregation._bucket_counts[3], 1 ) + histo = explicit_bucket_histogram_aggregation.collect() + self.assertEqual(histo.sum, 14) + def test_min_max(self): """ `record_min_max` indicates the aggregator to record the minimum and