28
28
from opentelemetry .sdk ._metrics ._internal .measurement import Measurement
29
29
from opentelemetry .sdk ._metrics ._internal .point import DataPointT
30
30
from opentelemetry .sdk ._metrics ._internal .view import View
31
+ from opentelemetry .util ._time import _time_ns
31
32
32
33
_logger = getLogger (__name__ )
33
34
@@ -39,6 +40,7 @@ def __init__(
39
40
instrument : Instrument ,
40
41
instrument_class_aggregation : Dict [type , Aggregation ],
41
42
):
43
+ self ._start_time_unix_nano = _time_ns ()
42
44
self ._view = view
43
45
self ._instrument = instrument
44
46
self ._attributes_aggregation : Dict [frozenset , _Aggregation ] = {}
@@ -50,12 +52,12 @@ def __init__(
50
52
)
51
53
if not isinstance (self ._view ._aggregation , DefaultAggregation ):
52
54
self ._aggregation = self ._view ._aggregation ._create_aggregation (
53
- self ._instrument , None
55
+ self ._instrument , None , 0
54
56
)
55
57
else :
56
58
self ._aggregation = self ._instrument_class_aggregation [
57
59
self ._instrument .__class__
58
- ]._create_aggregation (self ._instrument , None )
60
+ ]._create_aggregation (self ._instrument , None , 0 )
59
61
60
62
def conflicts (self , other : "_ViewInstrumentMatch" ) -> bool :
61
63
# pylint: disable=protected-access
@@ -103,21 +105,31 @@ def consume_measurement(self, measurement: Measurement) -> None:
103
105
):
104
106
aggregation = (
105
107
self ._view ._aggregation ._create_aggregation (
106
- self ._instrument , attributes
108
+ self ._instrument ,
109
+ attributes ,
110
+ self ._start_time_unix_nano ,
107
111
)
108
112
)
109
113
else :
110
114
aggregation = self ._instrument_class_aggregation [
111
115
self ._instrument .__class__
112
- ]._create_aggregation (self ._instrument , attributes )
116
+ ]._create_aggregation (
117
+ self ._instrument ,
118
+ attributes ,
119
+ self ._start_time_unix_nano ,
120
+ )
113
121
self ._attributes_aggregation [attributes ] = aggregation
114
122
115
123
self ._attributes_aggregation [attributes ].aggregate (measurement )
116
124
117
125
def collect (
118
- self , aggregation_temporality : AggregationTemporality
126
+ self ,
127
+ aggregation_temporality : AggregationTemporality ,
128
+ collection_start_nanos : int ,
119
129
) -> Iterable [DataPointT ]:
120
130
121
131
with self ._lock :
122
132
for aggregation in self ._attributes_aggregation .values ():
123
- yield aggregation .collect (aggregation_temporality )
133
+ yield aggregation .collect (
134
+ aggregation_temporality , collection_start_nanos
135
+ )
0 commit comments