From 60f7c59450c4c40d244a8fe6a842ea85b5bfdb5f Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 11 Sep 2023 15:47:11 +0200 Subject: [PATCH 1/3] Made NoOpSpan compatible to Transactions. --- sentry_sdk/tracing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 6967e95411..0c2e531a4b 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -853,6 +853,14 @@ def finish(self, hub=None, end_timestamp=None): # type: (Optional[sentry_sdk.Hub], Optional[datetime]) -> Optional[str] pass + def set_measurement(self, name, value, unit=""): + # type: (str, float, MeasurementUnit) -> None + pass + + def set_context(self, key, value): + # type: (str, Any) -> None + pass + def trace(func=None): # type: (Any) -> Any From 45d569727c8f188a793426ff3874a6284ef418f0 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 12 Sep 2023 08:21:44 +0200 Subject: [PATCH 2/3] Now all methods of Span an Transaction are in NoOpSpan --- sentry_sdk/tracing.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 0c2e531a4b..a96183846c 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -797,10 +797,31 @@ def _set_initial_sampling_decision(self, sampling_context): class NoOpSpan(Span): + def __init__( + self, + *args, # type: Any + **kwargs # type: Any + ): + # type: (...) -> None + pass + def __repr__(self): # type: () -> str return self.__class__.__name__ + def __enter__(self): + # type: () -> Span + return self + + def __exit__(self, ty, value, tb): + # type: (Optional[Any], Optional[Any], Optional[Any]) -> None + pass + + @property + def containing_transaction(self): + # type: () -> Optional[Transaction] + return None + def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs): # type: (str, **Any) -> NoOpSpan return NoOpSpan() @@ -817,6 +838,10 @@ def to_baggage(self): # type: () -> Optional[Baggage] return None + def get_baggage(self): + # type: () -> Optional[Baggage] + return None + def iter_headers(self): # type: () -> Iterator[Tuple[str, str]] return iter(()) @@ -861,6 +886,14 @@ def set_context(self, key, value): # type: (str, Any) -> None pass + def init_span_recorder(self, maxlen): + # type: (int) -> None + pass + + def _set_initial_sampling_decision(self, sampling_context): + # type: (SamplingContext) -> None + pass + def trace(func=None): # type: (Any) -> Any From d4d6d3449ef3a77ff3d2f6effa2226db2c96c98b Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 12 Sep 2023 12:22:01 +0200 Subject: [PATCH 3/3] Let NoOpSpan add itself to the scope, so the excepted behavior is kept --- sentry_sdk/tracing.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 8b0de81fbf..c646a40a8e 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -872,26 +872,10 @@ def _set_initial_sampling_decision(self, sampling_context): class NoOpSpan(Span): - def __init__( - self, - *args, # type: Any - **kwargs # type: Any - ): - # type: (...) -> None - pass - def __repr__(self): # type: () -> str return self.__class__.__name__ - def __enter__(self): - # type: () -> Span - return self - - def __exit__(self, ty, value, tb): - # type: (Optional[Any], Optional[Any], Optional[Any]) -> None - pass - @property def containing_transaction(self): # type: () -> Optional[Transaction]