Skip to content

ref(scope): Properly type Scope.root_span #4273

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

Merged
merged 3 commits into from
Apr 24, 2025
Merged
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
16 changes: 10 additions & 6 deletions sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ def _capture_exception(exc_info):
# type: (ExcInfo) -> None
scope = sentry_sdk.get_current_scope()

if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS:
scope.root_span.set_status(SPANSTATUS.ABORTED)
return
if scope.root_span is not None:
if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS:
scope.root_span.set_status(SPANSTATUS.ABORTED)
return

scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR)

scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR)
event, hint = event_from_exception(
exc_info,
client_options=sentry_sdk.get_client().options,
Expand All @@ -136,8 +138,10 @@ def _sentry_execute(*args, **kwargs):
exc_info = sys.exc_info()
_capture_exception(exc_info)
reraise(*exc_info)
else:
sentry_sdk.get_current_scope().root_span.set_status(SPANSTATUS.OK)

root_span = sentry_sdk.get_current_scope().root_span
if root_span is not None:
root_span.set_status(SPANSTATUS.OK)

return result

Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,7 @@ def fingerprint(self, value):

@property
def root_span(self):
# type: () -> Any
# would be type: () -> Optional[Span], see https://github.com/python/mypy/issues/3004
# type: () -> Optional[Span]
"""Return the root span in the scope, if any."""

# there is no span/transaction on the scope
Expand Down
Loading