Skip to content
Merged
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
53 changes: 25 additions & 28 deletions tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from celery import Celery, VERSION
from celery.bin import worker

from sentry_sdk import configure_scope, start_transaction, get_current_span
from sentry_sdk import Scope, start_transaction, get_current_span
from sentry_sdk.integrations.celery import (
CeleryIntegration,
_wrap_apply_async,
Expand Down Expand Up @@ -154,30 +154,31 @@ def dummy_task(x, y):
foo = 42 # noqa
return x / y

with configure_scope() as scope:
celery_invocation(dummy_task, 1, 2)
_, expected_context = celery_invocation(dummy_task, 1, 0)
scope = Scope.get_isolation_scope()

(error_event,) = events
celery_invocation(dummy_task, 1, 2)
_, expected_context = celery_invocation(dummy_task, 1, 0)

assert (
error_event["contexts"]["trace"]["trace_id"]
== scope._propagation_context.trace_id
)
assert (
error_event["contexts"]["trace"]["span_id"]
!= scope._propagation_context.span_id
)
assert error_event["transaction"] == "dummy_task"
assert "celery_task_id" in error_event["tags"]
assert error_event["extra"]["celery-job"] == dict(
task_name="dummy_task", **expected_context
)
(error_event,) = events

(exception,) = error_event["exception"]["values"]
assert exception["type"] == "ZeroDivisionError"
assert exception["mechanism"]["type"] == "celery"
assert exception["stacktrace"]["frames"][0]["vars"]["foo"] == "42"
assert (
error_event["contexts"]["trace"]["trace_id"]
== scope._propagation_context.trace_id
)
assert (
error_event["contexts"]["trace"]["span_id"]
!= scope._propagation_context.span_id
)
assert error_event["transaction"] == "dummy_task"
assert "celery_task_id" in error_event["tags"]
assert error_event["extra"]["celery-job"] == dict(
task_name="dummy_task", **expected_context
)

(exception,) = error_event["exception"]["values"]
assert exception["type"] == "ZeroDivisionError"
assert exception["mechanism"]["type"] == "celery"
assert exception["stacktrace"]["frames"][0]["vars"]["foo"] == "42"


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

@celery.task(name="dummy_task")
def dummy_task():
with configure_scope() as scope:
scope.set_tag("foo", "bar")

Scope.get_isolation_scope().set_tag("foo", "bar")
results.append(42)

for _ in range(10000):
dummy_task.delay()

assert results == [42] * 10000

with configure_scope() as scope:
assert not scope._tags
assert not Scope.get_isolation_scope()._tags


def test_simple_no_propagation(capture_events, init_celery):
Expand Down