From 3794a199da91a912668adea9e42d0da6f2f21379 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 8 Feb 2022 21:58:38 -0600 Subject: [PATCH] Set value to None This is done in order to identify the situation when aggregate has not been called before collect is. --- .../src/opentelemetry/sdk/_metrics/aggregation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py index c9585087746..56d416ef79a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py @@ -57,13 +57,15 @@ def __init__( super().__init__() self._instrument_is_monotonic = instrument_is_monotonic - self._value = 0 + self._value = None self._start_time_unix_nano = _time_ns() self._instrument_temporality = instrument_temporality def aggregate(self, measurement: Measurement) -> None: with self._lock: + if self._value is None: + self._value = 0 self._value = self._value + measurement.value def collect(self) -> Sum: @@ -78,7 +80,7 @@ def collect(self) -> Sum: value = self._value start_time_unix_nano = self._start_time_unix_nano - self._value = 0 + self._value = None self._start_time_unix_nano = now + 1 return Sum(