3535 UpDownCounter ,
3636 _Gauge ,
3737)
38- from opentelemetry .sdk .metrics ._internal .exemplar import Exemplar , ExemplarReservoirFactory
38+ from opentelemetry .sdk .metrics ._internal .exemplar import (
39+ Exemplar ,
40+ ExemplarReservoirFactory ,
41+ )
3942from opentelemetry .sdk .metrics ._internal .exponential_histogram .buckets import (
4043 Buckets ,
4144)
@@ -82,13 +85,19 @@ class AggregationTemporality(IntEnum):
8285
8386
8487class _Aggregation (ABC , Generic [_DataPointVarT ]):
85- def __init__ (self , attributes : Attributes , reservoir_factory : ExemplarReservoirFactory ):
88+ def __init__ (
89+ self ,
90+ attributes : Attributes ,
91+ reservoir_factory : ExemplarReservoirFactory ,
92+ ):
8693 self ._lock = Lock ()
8794 self ._attributes = attributes
8895 self ._reservoir = reservoir_factory ()
8996 self ._previous_point = None
9097
91- def aggregate (self , measurement : Measurement , should_sample_exemplar : bool = True ) -> None :
98+ def aggregate (
99+ self , measurement : Measurement , should_sample_exemplar : bool = True
100+ ) -> None :
92101 if should_sample_exemplar :
93102 self ._reservoir .offer (
94103 measurement .value ,
@@ -112,7 +121,9 @@ def _collect_exemplars(self) -> Sequence[Exemplar]:
112121
113122
114123class _DropAggregation (_Aggregation ):
115- def aggregate (self , measurement : Measurement , should_sample_exemplar : bool = True ) -> None :
124+ def aggregate (
125+ self , measurement : Measurement , should_sample_exemplar : bool = True
126+ ) -> None :
116127 pass
117128
118129 def collect (
@@ -135,15 +146,19 @@ def __init__(
135146 super ().__init__ (attributes , reservoir_factory )
136147
137148 self ._start_time_unix_nano = start_time_unix_nano
138- self ._instrument_aggregation_temporality = instrument_aggregation_temporality
149+ self ._instrument_aggregation_temporality = (
150+ instrument_aggregation_temporality
151+ )
139152 self ._instrument_is_monotonic = instrument_is_monotonic
140153
141154 self ._value = None
142155
143156 self ._previous_collection_start_nano = self ._start_time_unix_nano
144157 self ._previous_value = 0
145158
146- def aggregate (self , measurement : Measurement , should_sample_exemplar : bool = True ) -> None :
159+ def aggregate (
160+ self , measurement : Measurement , should_sample_exemplar : bool = True
161+ ) -> None :
147162 with self ._lock :
148163 if self ._value is None :
149164 self ._value = 0
@@ -363,14 +378,20 @@ def collect(
363378
364379
365380class _LastValueAggregation (_Aggregation [GaugePoint ]):
366- def __init__ (self , attributes : Attributes , reservoir_factory : ExemplarReservoirFactory ):
381+ def __init__ (
382+ self ,
383+ attributes : Attributes ,
384+ reservoir_factory : ExemplarReservoirFactory ,
385+ ):
367386 super ().__init__ (attributes , reservoir_factory )
368387 self ._value = None
369388
370- def aggregate (self , measurement : Measurement , should_sample_exemplar : bool = True ):
389+ def aggregate (
390+ self , measurement : Measurement , should_sample_exemplar : bool = True
391+ ):
371392 with self ._lock :
372393 self ._value = measurement .value
373-
394+
374395 super ().aggregate (measurement , should_sample_exemplar )
375396
376397 def collect (
@@ -424,7 +445,12 @@ def __init__(
424445 ),
425446 record_min_max : bool = True ,
426447 ):
427- super ().__init__ (attributes , reservoir_factory = partial (reservoir_factory , boundaries = boundaries ))
448+ super ().__init__ (
449+ attributes ,
450+ reservoir_factory = partial (
451+ reservoir_factory , boundaries = boundaries
452+ ),
453+ )
428454
429455 self ._instrument_aggregation_temporality = (
430456 instrument_aggregation_temporality
@@ -448,7 +474,9 @@ def __init__(
448474 def _get_empty_bucket_counts (self ) -> List [int ]:
449475 return [0 ] * (len (self ._boundaries ) + 1 )
450476
451- def aggregate (self , measurement : Measurement , should_sample_exemplar : bool = True ) -> None :
477+ def aggregate (
478+ self , measurement : Measurement , should_sample_exemplar : bool = True
479+ ) -> None :
452480
453481 with self ._lock :
454482 if self ._value is None :
@@ -615,7 +643,12 @@ def __init__(
615643 # _ExplicitBucketHistogramAggregation both size and amount of buckets
616644 # remain constant once it is instantiated).
617645
618- super ().__init__ (attributes , reservoir_factory = partial (reservoir_factory , size = min (20 , max_size )))
646+ super ().__init__ (
647+ attributes ,
648+ reservoir_factory = partial (
649+ reservoir_factory , size = min (20 , max_size )
650+ ),
651+ )
619652
620653 self ._instrument_aggregation_temporality = (
621654 instrument_aggregation_temporality
@@ -646,7 +679,9 @@ def __init__(
646679
647680 self ._mapping = self ._new_mapping (self ._max_scale )
648681
649- def aggregate (self , measurement : Measurement , should_sample_exemplar : bool = True ) -> None :
682+ def aggregate (
683+ self , measurement : Measurement , should_sample_exemplar : bool = True
684+ ) -> None :
650685 # pylint: disable=too-many-branches,too-many-statements, too-many-locals
651686
652687 with self ._lock :
@@ -1147,7 +1182,9 @@ def _create_aggregation(
11471182 self ,
11481183 instrument : Instrument ,
11491184 attributes : Attributes ,
1150- reservoir_factory : Callable [[Type [_Aggregation ]], ExemplarReservoirFactory ],
1185+ reservoir_factory : Callable [
1186+ [Type [_Aggregation ]], ExemplarReservoirFactory
1187+ ],
11511188 start_time_unix_nano : int ,
11521189 ) -> _Aggregation :
11531190 """Creates an aggregation"""
@@ -1176,7 +1213,9 @@ def _create_aggregation(
11761213 self ,
11771214 instrument : Instrument ,
11781215 attributes : Attributes ,
1179- reservoir_factory : Callable [[Type [_Aggregation ]], ExemplarReservoirFactory ],
1216+ reservoir_factory : Callable [
1217+ [Type [_Aggregation ]], ExemplarReservoirFactory
1218+ ],
11801219 start_time_unix_nano : int ,
11811220 ) -> _Aggregation :
11821221
@@ -1227,18 +1266,26 @@ def _create_aggregation(
12271266 if isinstance (instrument , Histogram ):
12281267 return _ExplicitBucketHistogramAggregation (
12291268 attributes ,
1230- reservoir_factory = reservoir_factory (_ExplicitBucketHistogramAggregation ),
1269+ reservoir_factory = reservoir_factory (
1270+ _ExplicitBucketHistogramAggregation
1271+ ),
12311272 instrument_aggregation_temporality = (
12321273 AggregationTemporality .DELTA
12331274 ),
12341275 start_time_unix_nano = start_time_unix_nano ,
12351276 )
12361277
12371278 if isinstance (instrument , ObservableGauge ):
1238- return _LastValueAggregation (attributes , reservoir_factory = reservoir_factory (_LastValueAggregation ))
1279+ return _LastValueAggregation (
1280+ attributes ,
1281+ reservoir_factory = reservoir_factory (_LastValueAggregation ),
1282+ )
12391283
12401284 if isinstance (instrument , _Gauge ):
1241- return _LastValueAggregation (attributes , reservoir_factory = reservoir_factory (_LastValueAggregation ))
1285+ return _LastValueAggregation (
1286+ attributes ,
1287+ reservoir_factory = reservoir_factory (_LastValueAggregation ),
1288+ )
12421289
12431290 # pylint: disable=broad-exception-raised
12441291 raise Exception (f"Invalid instrument type { type (instrument )} found" )
@@ -1257,7 +1304,9 @@ def _create_aggregation(
12571304 self ,
12581305 instrument : Instrument ,
12591306 attributes : Attributes ,
1260- reservoir_factory : Callable [[Type [_Aggregation ]], ExemplarReservoirFactory ],
1307+ reservoir_factory : Callable [
1308+ [Type [_Aggregation ]], ExemplarReservoirFactory
1309+ ],
12611310 start_time_unix_nano : int ,
12621311 ) -> _Aggregation :
12631312
@@ -1321,7 +1370,9 @@ def _create_aggregation(
13211370 self ,
13221371 instrument : Instrument ,
13231372 attributes : Attributes ,
1324- reservoir_factory : Callable [[Type [_Aggregation ]], ExemplarReservoirFactory ],
1373+ reservoir_factory : Callable [
1374+ [Type [_Aggregation ]], ExemplarReservoirFactory
1375+ ],
13251376 start_time_unix_nano : int ,
13261377 ) -> _Aggregation :
13271378
@@ -1353,7 +1404,9 @@ def _create_aggregation(
13531404 self ,
13541405 instrument : Instrument ,
13551406 attributes : Attributes ,
1356- reservoir_factory : Callable [[Type [_Aggregation ]], ExemplarReservoirFactory ],
1407+ reservoir_factory : Callable [
1408+ [Type [_Aggregation ]], ExemplarReservoirFactory
1409+ ],
13571410 start_time_unix_nano : int ,
13581411 ) -> _Aggregation :
13591412
@@ -1386,10 +1439,15 @@ def _create_aggregation(
13861439 self ,
13871440 instrument : Instrument ,
13881441 attributes : Attributes ,
1389- reservoir_factory : Callable [[Type [_Aggregation ]], ExemplarReservoirFactory ],
1442+ reservoir_factory : Callable [
1443+ [Type [_Aggregation ]], ExemplarReservoirFactory
1444+ ],
13901445 start_time_unix_nano : int ,
13911446 ) -> _Aggregation :
1392- return _LastValueAggregation (attributes , reservoir_factory = reservoir_factory (_LastValueAggregation ))
1447+ return _LastValueAggregation (
1448+ attributes ,
1449+ reservoir_factory = reservoir_factory (_LastValueAggregation ),
1450+ )
13931451
13941452
13951453class DropAggregation (Aggregation ):
@@ -1399,7 +1457,11 @@ def _create_aggregation(
13991457 self ,
14001458 instrument : Instrument ,
14011459 attributes : Attributes ,
1402- reservoir_factory : Callable [[Type [_Aggregation ]], ExemplarReservoirFactory ],
1460+ reservoir_factory : Callable [
1461+ [Type [_Aggregation ]], ExemplarReservoirFactory
1462+ ],
14031463 start_time_unix_nano : int ,
14041464 ) -> _Aggregation :
1405- return _DropAggregation (attributes , reservoir_factory (_DropAggregation ))
1465+ return _DropAggregation (
1466+ attributes , reservoir_factory (_DropAggregation )
1467+ )
0 commit comments