Skip to content

Commit 19b2db4

Browse files
committed
Fix code and unit tests
1 parent 80f040d commit 19b2db4

File tree

5 files changed

+335
-101
lines changed

5 files changed

+335
-101
lines changed

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def collect(self, point_attributes: Attributes) -> list[Exemplar]:
6868
class ExemplarBucket:
6969
def __init__(self) -> None:
7070
self.__value: Union[int, float] = 0
71-
self.__attributes: Attributes = {}
71+
self.__attributes: Attributes = None
7272
self.__time_unix_nano: int = 0
7373
self.__span_id: Optional[str] = None
7474
self.__trace_id: Optional[str] = None
@@ -98,11 +98,15 @@ def collect(self, point_attributes: Attributes) -> Exemplar | None:
9898
if not self.__offered:
9999
return None
100100

101-
current_attributes = {
102-
k: v
103-
for k, v in self.__attributes.items()
104-
if k not in point_attributes
105-
}
101+
current_attributes = (
102+
{
103+
k: v
104+
for k, v in self.__attributes.items()
105+
if k not in point_attributes
106+
}
107+
if self.__attributes
108+
else None
109+
)
106110

107111
exemplar = Exemplar(
108112
current_attributes,
@@ -157,7 +161,7 @@ def collect(self, point_attributes: Attributes) -> list[Exemplar]:
157161
),
158162
)
159163
self._reset()
160-
return [exemplars]
164+
return [*exemplars]
161165

162166
def _reset(self) -> None:
163167
"""Reset the reservoir."""

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ def callback(
141141
api_measurement.value,
142142
time_unix_nano=time_ns(),
143143
instrument=self,
144-
attributes=api_measurement.attributes,
145144
context=api_measurement.context or get_current(),
145+
attributes=api_measurement.attributes,
146146
)
147147
except Exception: # pylint: disable=broad-exception-caught
148148
_logger.exception(
@@ -173,8 +173,8 @@ def add(
173173
amount,
174174
time_unix_nano,
175175
self,
176-
attributes,
177176
context or get_current(),
177+
attributes,
178178
)
179179
)
180180

@@ -197,8 +197,8 @@ def add(
197197
amount,
198198
time_unix_nano,
199199
self,
200-
attributes,
201200
context or get_current(),
201+
attributes,
202202
)
203203
)
204204

@@ -245,8 +245,8 @@ def record(
245245
amount,
246246
time_unix_nano,
247247
self,
248-
attributes,
249248
context or get_current(),
249+
attributes,
250250
)
251251
)
252252

@@ -269,8 +269,8 @@ def set(
269269
amount,
270270
time_unix_nano,
271271
self,
272-
attributes,
273272
context or get_current(),
273+
attributes,
274274
)
275275
)
276276

0 commit comments

Comments
 (0)