From 7db8e99f86b20c6dd2386f34750ec7fc93499340 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 25 Oct 2021 14:24:02 +0200 Subject: [PATCH] Add timestamp for last value --- .../src/opentelemetry/sdk/metrics/aggregation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/aggregation.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/aggregation.py index 1a592db1a84..066847d9ad9 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/aggregation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/aggregation.py @@ -20,6 +20,7 @@ AGGREGATION_TEMPORALITY_CUMULATIVE, AGGREGATION_TEMPORALITY_DELTA, ) +from opentelemetry.util._time import _time_ns class Aggregation(ABC): @@ -77,8 +78,13 @@ class LastValueAggregation(Aggregation): This aggregation collects data for the SDK sum metric point. """ + def __init__(self): + super().__init__() + self._timestamp = _time_ns() + def aggregate(self, value): self._value = value + self._timestamp = _time_ns() def collect(self): return self._value