Skip to content

Commit f6a14ce

Browse files
committed
Don't request current context when creating a measurement
1 parent 06809f4 commit f6a14ce

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from abc import ABC, abstractmethod
16-
from typing import Union
16+
from typing import Optional, Union
1717

1818
from opentelemetry import trace
1919
from opentelemetry.context import Context
@@ -38,7 +38,7 @@ def should_sample(
3838
value: Union[int, float],
3939
time_unix_nano: int,
4040
attributes: Attributes,
41-
context: Context,
41+
context: Optional[Context],
4242
) -> bool:
4343
"""Returns whether or not a reservoir should attempt to filter a measurement.
4444
@@ -65,7 +65,7 @@ def should_sample(
6565
value: Union[int, float],
6666
time_unix_nano: int,
6767
attributes: Attributes,
68-
context: Context,
68+
context: Optional[Context],
6969
) -> bool:
7070
"""Returns whether or not a reservoir should attempt to filter a measurement.
7171
@@ -92,7 +92,7 @@ def should_sample(
9292
value: Union[int, float],
9393
time_unix_nano: int,
9494
attributes: Attributes,
95-
context: Context,
95+
context: Optional[Context],
9696
) -> bool:
9797
"""Returns whether or not a reservoir should attempt to filter a measurement.
9898
@@ -118,7 +118,7 @@ def should_sample(
118118
value: Union[int, float],
119119
time_unix_nano: int,
120120
attributes: Attributes,
121-
context: Context,
121+
context: Optional[Context],
122122
) -> bool:
123123
"""Returns whether or not a reservoir should attempt to filter a measurement.
124124

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# This kind of import is needed to avoid Sphinx errors.
2222
import opentelemetry.sdk.metrics
23-
from opentelemetry.context import Context, get_current
23+
from opentelemetry.context import Context
2424
from opentelemetry.metrics import CallbackT
2525
from opentelemetry.metrics import Counter as APICounter
2626
from opentelemetry.metrics import Histogram as APIHistogram
@@ -138,7 +138,7 @@ def callback(
138138
api_measurement.value,
139139
time_unix_nano=time_ns(),
140140
instrument=self,
141-
context=api_measurement.context or get_current(),
141+
context=api_measurement.context,
142142
attributes=api_measurement.attributes,
143143
)
144144
except Exception: # pylint: disable=broad-exception-caught
@@ -170,7 +170,7 @@ def add(
170170
amount,
171171
time_unix_nano,
172172
self,
173-
context or get_current(),
173+
context,
174174
attributes,
175175
)
176176
)
@@ -194,7 +194,7 @@ def add(
194194
amount,
195195
time_unix_nano,
196196
self,
197-
context or get_current(),
197+
context,
198198
attributes,
199199
)
200200
)
@@ -242,7 +242,7 @@ def record(
242242
amount,
243243
time_unix_nano,
244244
self,
245-
context or get_current(),
245+
context,
246246
attributes,
247247
)
248248
)
@@ -266,7 +266,7 @@ def set(
266266
amount,
267267
time_unix_nano,
268268
self,
269-
context or get_current(),
269+
context,
270270
attributes,
271271
)
272272
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from dataclasses import dataclass
16-
from typing import Union
16+
from typing import Optional, Union
1717

1818
from opentelemetry.context import Context
1919
from opentelemetry.metrics import Instrument
@@ -41,5 +41,5 @@ class Measurement:
4141
value: Union[int, float]
4242
time_unix_nano: int
4343
instrument: Instrument
44-
context: Context
44+
context: Optional[Context] = None
4545
attributes: Attributes = None

0 commit comments

Comments
 (0)