Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance: Don't request current context when creating a measurement #4253

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading