Skip to content

Commit ab408f2

Browse files
test(celery): Stop using configure_scope
Use `Scope.get_isolation_scope` instead. Ref #3344
1 parent 18015e9 commit ab408f2

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

tests/integrations/celery/test_celery.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from celery import Celery, VERSION
77
from celery.bin import worker
88

9-
from sentry_sdk import configure_scope, start_transaction, get_current_span
9+
from sentry_sdk import Scope, start_transaction, get_current_span
1010
from sentry_sdk.integrations.celery import (
1111
CeleryIntegration,
1212
_wrap_apply_async,
@@ -154,30 +154,31 @@ def dummy_task(x, y):
154154
foo = 42 # noqa
155155
return x / y
156156

157-
with configure_scope() as scope:
158-
celery_invocation(dummy_task, 1, 2)
159-
_, expected_context = celery_invocation(dummy_task, 1, 0)
157+
scope = Scope.get_isolation_scope()
160158

161-
(error_event,) = events
159+
celery_invocation(dummy_task, 1, 2)
160+
_, expected_context = celery_invocation(dummy_task, 1, 0)
162161

163-
assert (
164-
error_event["contexts"]["trace"]["trace_id"]
165-
== scope._propagation_context.trace_id
166-
)
167-
assert (
168-
error_event["contexts"]["trace"]["span_id"]
169-
!= scope._propagation_context.span_id
170-
)
171-
assert error_event["transaction"] == "dummy_task"
172-
assert "celery_task_id" in error_event["tags"]
173-
assert error_event["extra"]["celery-job"] == dict(
174-
task_name="dummy_task", **expected_context
175-
)
162+
(error_event,) = events
176163

177-
(exception,) = error_event["exception"]["values"]
178-
assert exception["type"] == "ZeroDivisionError"
179-
assert exception["mechanism"]["type"] == "celery"
180-
assert exception["stacktrace"]["frames"][0]["vars"]["foo"] == "42"
164+
assert (
165+
error_event["contexts"]["trace"]["trace_id"]
166+
== scope._propagation_context.trace_id
167+
)
168+
assert (
169+
error_event["contexts"]["trace"]["span_id"]
170+
!= scope._propagation_context.span_id
171+
)
172+
assert error_event["transaction"] == "dummy_task"
173+
assert "celery_task_id" in error_event["tags"]
174+
assert error_event["extra"]["celery-job"] == dict(
175+
task_name="dummy_task", **expected_context
176+
)
177+
178+
(exception,) = error_event["exception"]["values"]
179+
assert exception["type"] == "ZeroDivisionError"
180+
assert exception["mechanism"]["type"] == "celery"
181+
assert exception["stacktrace"]["frames"][0]["vars"]["foo"] == "42"
181182

182183

183184
@pytest.mark.parametrize("task_fails", [True, False], ids=["error", "success"])
@@ -255,18 +256,14 @@ def test_no_stackoverflows(celery):
255256

256257
@celery.task(name="dummy_task")
257258
def dummy_task():
258-
with configure_scope() as scope:
259-
scope.set_tag("foo", "bar")
260-
259+
Scope.get_isolation_scope().set_tag("foo", "bar")
261260
results.append(42)
262261

263262
for _ in range(10000):
264263
dummy_task.delay()
265264

266265
assert results == [42] * 10000
267-
268-
with configure_scope() as scope:
269-
assert not scope._tags
266+
assert not Scope.get_current_scope()._tags
270267

271268

272269
def test_simple_no_propagation(capture_events, init_celery):

0 commit comments

Comments
 (0)