diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py index 8961d101ef..867853a427 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py @@ -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 @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/instrument.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/instrument.py index c93f83a4e6..6eb07185c8 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/instrument.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/instrument.py @@ -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 @@ -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 @@ -170,7 +170,7 @@ def add( amount, time_unix_nano, self, - context or get_current(), + context, attributes, ) ) @@ -194,7 +194,7 @@ def add( amount, time_unix_nano, self, - context or get_current(), + context, attributes, ) ) @@ -242,7 +242,7 @@ def record( amount, time_unix_nano, self, - context or get_current(), + context, attributes, ) ) @@ -266,7 +266,7 @@ def set( amount, time_unix_nano, self, - context or get_current(), + context, attributes, ) ) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement.py index 56619a83a1..c07c2da92c 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement.py @@ -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 @@ -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