Skip to content

Commit 6e9e5ee

Browse files
committed
ref(celery): Use hub.trace
1 parent 3d63842 commit 6e9e5ee

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

sentry_sdk/integrations/celery.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,19 @@ def _inner(*args, **kwargs):
9090
with hub.push_scope() as scope:
9191
scope._name = "celery"
9292
scope.clear_breadcrumbs()
93-
span = _continue_trace(args[3].get("headers") or {}, scope)
93+
scope.add_event_processor(_make_event_processor(task, *args, **kwargs))
9494

9595
with capture_internal_exceptions():
96+
# Celery task objects are not a thing to be trusted. Even
97+
# something such as attribute access can fail.
9698
scope.transaction = task.name
9799

98-
scope.add_event_processor(_make_event_processor(task, *args, **kwargs))
99-
100-
try:
100+
with hub.trace(Span.continue_from_headers(args[3].get("headers") or {})):
101101
return f(*args, **kwargs)
102-
finally:
103-
span.finish()
104-
hub.finish_trace(span)
105102

106103
return _inner
107104

108105

109-
def _continue_trace(headers, scope):
110-
if headers:
111-
span = Span.continue_from_headers(headers)
112-
else:
113-
span = Span.start_trace()
114-
115-
scope.span = span
116-
return span
117-
118-
119106
def _wrap_task_call(task, f):
120107
# Need to wrap task call because the exception is caught before we get to
121108
# see it. Also celery's reported stacktrace is untrustworthy.

0 commit comments

Comments
 (0)