Skip to content

Commit bd9e0a3

Browse files
committed
add finished to noop span
1 parent 73e33ea commit bd9e0a3

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

sentry_sdk/traces.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,10 @@ def timestamp(self) -> "Optional[datetime]":
447447

448448

449449
class NoOpStreamedSpan(StreamedSpan):
450-
__slots__ = ("_unsampled_reason",)
450+
__slots__ = (
451+
"_finished",
452+
"_unsampled_reason",
453+
)
451454

452455
def __init__(
453456
self,
@@ -479,6 +482,9 @@ def _start(self) -> None:
479482
self._previous_span_on_scope = old_span
480483

481484
def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None:
485+
if self._finished:
486+
return
487+
482488
client = sentry_sdk.get_client()
483489
if client.is_active() and client.transport:
484490
logger.debug("Discarding span because sampled = False")
@@ -488,13 +494,13 @@ def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None
488494
quantity=1,
489495
)
490496

491-
if self._scope is None or not hasattr(self, "_previous_span_on_scope"):
492-
return
497+
if self._scope:
498+
with capture_internal_exceptions():
499+
old_span = self._previous_span_on_scope
500+
del self._previous_span_on_scope
501+
self._scope.span = old_span
493502

494-
with capture_internal_exceptions():
495-
old_span = self._previous_span_on_scope
496-
del self._previous_span_on_scope
497-
self._scope.span = old_span
503+
self._finished = True
498504

499505
def end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None:
500506
self._end()

0 commit comments

Comments
 (0)