|
6 | 6 | from celery import Celery, VERSION
|
7 | 7 | from celery.bin import worker
|
8 | 8 |
|
9 |
| -from sentry_sdk import configure_scope, start_transaction, get_current_span |
| 9 | +from sentry_sdk import Scope, start_transaction, get_current_span |
10 | 10 | from sentry_sdk.integrations.celery import (
|
11 | 11 | CeleryIntegration,
|
12 | 12 | _wrap_apply_async,
|
@@ -154,30 +154,31 @@ def dummy_task(x, y):
|
154 | 154 | foo = 42 # noqa
|
155 | 155 | return x / y
|
156 | 156 |
|
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() |
160 | 158 |
|
161 |
| - (error_event,) = events |
| 159 | + celery_invocation(dummy_task, 1, 2) |
| 160 | + _, expected_context = celery_invocation(dummy_task, 1, 0) |
162 | 161 |
|
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 |
176 | 163 |
|
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" |
181 | 182 |
|
182 | 183 |
|
183 | 184 | @pytest.mark.parametrize("task_fails", [True, False], ids=["error", "success"])
|
@@ -255,18 +256,14 @@ def test_no_stackoverflows(celery):
|
255 | 256 |
|
256 | 257 | @celery.task(name="dummy_task")
|
257 | 258 | 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") |
261 | 260 | results.append(42)
|
262 | 261 |
|
263 | 262 | for _ in range(10000):
|
264 | 263 | dummy_task.delay()
|
265 | 264 |
|
266 | 265 | assert results == [42] * 10000
|
267 |
| - |
268 |
| - with configure_scope() as scope: |
269 |
| - assert not scope._tags |
| 266 | + assert not Scope.get_current_scope()._tags |
270 | 267 |
|
271 | 268 |
|
272 | 269 | def test_simple_no_propagation(capture_events, init_celery):
|
|
0 commit comments