Skip to content
Closed
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
14 changes: 1 addition & 13 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,21 +878,9 @@ def set_user(self, value: "Optional[Dict[str, Any]]") -> None:

@property
def span(self) -> "Optional[Union[Span, StreamedSpan]]":
"""Get/set current tracing span or transaction."""
"""Get current tracing span or transaction."""
return self._span

@span.setter
def span(self, span: "Optional[Union[Span, StreamedSpan]]") -> None:
self._span = span
# XXX: this differs from the implementation in JS, there Scope.setSpan
# does not set Scope._transactionName.
if isinstance(span, Transaction):
transaction = span
if transaction.name:
self._transaction = transaction.name
if transaction.source:
self._transaction_info["source"] = transaction.source

@property
def profile(self) -> "Optional[Profile]":
return self._profile
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def finish(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> No
def _start(self) -> None:
if self._active:
old_span = self._scope.span
self._scope.span = self
self._scope._span = self
self._previous_span_on_scope = old_span

def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None:
Expand All @@ -361,7 +361,7 @@ def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None
with capture_internal_exceptions():
old_span = self._previous_span_on_scope
del self._previous_span_on_scope
self._scope.span = old_span
self._scope._span = old_span

# Set attributes from the segment. These are set on span end on purpose
# so that we have the best chance to capture the segment's final name
Expand Down Expand Up @@ -591,7 +591,7 @@ def _start(self) -> None:
return

old_span = self._scope.span
self._scope.span = self
self._scope._span = self
self._previous_span_on_scope = old_span

def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None:
Expand All @@ -614,7 +614,7 @@ def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None
with capture_internal_exceptions():
old_span = self._previous_span_on_scope
del self._previous_span_on_scope
self._scope.span = old_span
self._scope._span = old_span

self._finished = True

Expand Down
11 changes: 9 additions & 2 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def __repr__(self) -> str:
def __enter__(self) -> "Span":
scope = self.scope or sentry_sdk.get_current_scope()
old_span = scope.span
scope.span = self
scope._span = self
self._context_manager_state = (scope, old_span)
return self

Expand All @@ -402,7 +402,7 @@ def __exit__(
scope, old_span = self._context_manager_state
del self._context_manager_state
self.finish(scope)
scope.span = old_span
scope._span = old_span

@property
def containing_transaction(self) -> "Optional[Transaction]":
Expand Down Expand Up @@ -874,6 +874,13 @@ def __enter__(self) -> "Transaction":

super().__enter__()

# Propagate transaction name and source to the scope
scope = self.scope or sentry_sdk.get_current_scope()
if self.name:
scope._transaction = self.name
if self.source:
scope._transaction_info["source"] = self.source

if self._profile is not None:
self._profile.__enter__()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_get_current_span_default_hub(sentry_init):

scope = get_current_scope()
fake_span = mock.MagicMock()
scope.span = fake_span
scope._span = fake_span

assert get_current_span() == fake_span

Expand Down
Loading