Skip to content

Commit 80f040d

Browse files
committed
Lint the code
1 parent 5fc775b commit 80f040d

File tree

17 files changed

+353
-124
lines changed

17 files changed

+353
-124
lines changed

opentelemetry-api/src/opentelemetry/metrics/_internal/observation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class Observation:
3030
"""
3131

3232
def __init__(
33-
self, value: Union[int, float], attributes: Attributes = None, context: Optional[Context] = None
33+
self,
34+
value: Union[int, float],
35+
attributes: Attributes = None,
36+
context: Optional[Context] = None,
3437
) -> None:
3538
self._value = value
3639
self._attributes = attributes
@@ -43,7 +46,7 @@ def value(self) -> Union[float, int]:
4346
@property
4447
def attributes(self) -> Attributes:
4548
return self._attributes
46-
49+
4750
@property
4851
def context(self) -> Optional[Context]:
4952
return self._context

opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
from opentelemetry.sdk.metrics._internal import Meter, MeterProvider
1717
from opentelemetry.sdk.metrics._internal.exceptions import MetricsTimeoutError
18-
from opentelemetry.sdk.metrics._internal.exemplar import ExemplarFilter, ExemplarReservoir
18+
from opentelemetry.sdk.metrics._internal.exemplar import (
19+
ExemplarFilter,
20+
ExemplarReservoir,
21+
)
1922
from opentelemetry.sdk.metrics._internal.instrument import Counter
2023
from opentelemetry.sdk.metrics._internal.instrument import Gauge as _Gauge
2124
from opentelemetry.sdk.metrics._internal.instrument import (

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
from opentelemetry.metrics import _Gauge as APIGauge
3636
from opentelemetry.sdk.environment_variables import OTEL_SDK_DISABLED
3737
from opentelemetry.sdk.metrics._internal.exceptions import MetricsTimeoutError
38-
from opentelemetry.sdk.metrics._internal.exemplar import ExemplarFilter, TraceBasedExemplarFilter
38+
from opentelemetry.sdk.metrics._internal.exemplar import (
39+
ExemplarFilter,
40+
TraceBasedExemplarFilter,
41+
)
3942
from opentelemetry.sdk.metrics._internal.instrument import (
4043
_Counter,
4144
_Gauge,
@@ -392,7 +395,11 @@ def __init__(
392395
if resource is None:
393396
resource = Resource.create({})
394397
self._sdk_config = SdkConfiguration(
395-
exemplar_filter = TraceBasedExemplarFilter() if exemplar_filter is None else exemplar_filter,
398+
exemplar_filter=(
399+
TraceBasedExemplarFilter()
400+
if exemplar_filter is None
401+
else exemplar_filter
402+
),
396403
resource=resource,
397404
metric_readers=metric_readers,
398405
views=views,

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@ def __init__(
5252
)
5353
if not isinstance(self._view._aggregation, DefaultAggregation):
5454
self._aggregation = self._view._aggregation._create_aggregation(
55-
self._instrument, None, self._view._exemplar_reservoir_factory, 0
55+
self._instrument,
56+
None,
57+
self._view._exemplar_reservoir_factory,
58+
0,
5659
)
5760
else:
5861
self._aggregation = self._instrument_class_aggregation[
5962
self._instrument.__class__
6063
]._create_aggregation(
61-
self._instrument, None, self._view._exemplar_reservoir_factory, 0
64+
self._instrument,
65+
None,
66+
self._view._exemplar_reservoir_factory,
67+
0,
6268
)
6369

6470
def conflicts(self, other: "_ViewInstrumentMatch") -> bool:
@@ -83,7 +89,9 @@ def conflicts(self, other: "_ViewInstrumentMatch") -> bool:
8389
return result
8490

8591
# pylint: disable=protected-access
86-
def consume_measurement(self, measurement: Measurement, should_sample_exemplar: bool = True) -> None:
92+
def consume_measurement(
93+
self, measurement: Measurement, should_sample_exemplar: bool = True
94+
) -> None:
8795

8896
if self._view._attribute_keys is not None:
8997

@@ -124,7 +132,9 @@ def consume_measurement(self, measurement: Measurement, should_sample_exemplar:
124132
)
125133
self._attributes_aggregation[aggr_key] = aggregation
126134

127-
self._attributes_aggregation[aggr_key].aggregate(measurement, should_sample_exemplar)
135+
self._attributes_aggregation[aggr_key].aggregate(
136+
measurement, should_sample_exemplar
137+
)
128138

129139
def collect(
130140
self,

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
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+
)
3942
from opentelemetry.sdk.metrics._internal.exponential_histogram.buckets import (
4043
Buckets,
4144
)
@@ -82,13 +85,19 @@ class AggregationTemporality(IntEnum):
8285

8386

8487
class _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

114123
class _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

365380
class _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

13951453
class 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+
)

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
from .exemplar import Exemplar
1616
from .exemplar_filter import (
17-
ExemplarFilter,
1817
AlwaysOffExemplarFilter,
1918
AlwaysOnExemplarFilter,
19+
ExemplarFilter,
2020
TraceBasedExemplarFilter,
2121
)
2222
from .exemplar_reservoir import (

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/exemplar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class Exemplar:
3737
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#exemplars
3838
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#exemplar
3939
"""
40+
4041
filtered_attributes: Attributes
4142
value: Union[int, float]
4243
time_unix_nano: int
4344
span_id: Optional[str] = None
4445
trace_id: Optional[str] = None
45-

0 commit comments

Comments
 (0)