Skip to content

Commit

Permalink
Don't request current context when creating a measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Nov 6, 2024
1 parent 06809f4 commit f6a14ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from abc import ABC, abstractmethod
from typing import Union
from typing import Optional, Union

from opentelemetry import trace
from opentelemetry.context import Context
Expand All @@ -38,7 +38,7 @@ def should_sample(
value: Union[int, float],
time_unix_nano: int,
attributes: Attributes,
context: Context,
context: Optional[Context],
) -> bool:
"""Returns whether or not a reservoir should attempt to filter a measurement.
Expand All @@ -65,7 +65,7 @@ def should_sample(
value: Union[int, float],
time_unix_nano: int,
attributes: Attributes,
context: Context,
context: Optional[Context],
) -> bool:
"""Returns whether or not a reservoir should attempt to filter a measurement.
Expand All @@ -92,7 +92,7 @@ def should_sample(
value: Union[int, float],
time_unix_nano: int,
attributes: Attributes,
context: Context,
context: Optional[Context],
) -> bool:
"""Returns whether or not a reservoir should attempt to filter a measurement.
Expand All @@ -118,7 +118,7 @@ def should_sample(
value: Union[int, float],
time_unix_nano: int,
attributes: Attributes,
context: Context,
context: Optional[Context],
) -> bool:
"""Returns whether or not a reservoir should attempt to filter a measurement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# This kind of import is needed to avoid Sphinx errors.
import opentelemetry.sdk.metrics
from opentelemetry.context import Context, get_current
from opentelemetry.context import Context
from opentelemetry.metrics import CallbackT
from opentelemetry.metrics import Counter as APICounter
from opentelemetry.metrics import Histogram as APIHistogram
Expand Down Expand Up @@ -138,7 +138,7 @@ def callback(
api_measurement.value,
time_unix_nano=time_ns(),
instrument=self,
context=api_measurement.context or get_current(),
context=api_measurement.context,
attributes=api_measurement.attributes,
)
except Exception: # pylint: disable=broad-exception-caught
Expand Down Expand Up @@ -170,7 +170,7 @@ def add(
amount,
time_unix_nano,
self,
context or get_current(),
context,
attributes,
)
)
Expand All @@ -194,7 +194,7 @@ def add(
amount,
time_unix_nano,
self,
context or get_current(),
context,
attributes,
)
)
Expand Down Expand Up @@ -242,7 +242,7 @@ def record(
amount,
time_unix_nano,
self,
context or get_current(),
context,
attributes,
)
)
Expand All @@ -266,7 +266,7 @@ def set(
amount,
time_unix_nano,
self,
context or get_current(),
context,
attributes,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from dataclasses import dataclass
from typing import Union
from typing import Optional, Union

from opentelemetry.context import Context
from opentelemetry.metrics import Instrument
Expand Down Expand Up @@ -41,5 +41,5 @@ class Measurement:
value: Union[int, float]
time_unix_nano: int
instrument: Instrument
context: Context
context: Optional[Context] = None
attributes: Attributes = None

0 comments on commit f6a14ce

Please sign in to comment.