Skip to content

Commit

Permalink
Set value to None
Browse files Browse the repository at this point in the history
This is done in order to identify the situation when aggregate has not
been called before collect is.
  • Loading branch information
ocelotl committed Feb 9, 2022
1 parent 34c7758 commit 435ee41
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down

0 comments on commit 435ee41

Please sign in to comment.