Skip to content

Commit 8a6cc39

Browse files
committed
.
1 parent 3158781 commit 8a6cc39

File tree

2 files changed

+3
-52
lines changed

2 files changed

+3
-52
lines changed

sentry_sdk/integrations/django/tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import sentry_sdk
44
from sentry_sdk.consts import OP
5+
from sentry_sdk.tracing import SPANSTATUS
56

67
try:
78
# django.tasks were added in Django 6.0
8-
from django.tasks.base import Task
9+
from django.tasks.base import Task, TaskResultStatus
910
except ImportError:
1011
Task = None
1112

tests/integrations/django/test_tasks.py

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_task_error_reporting(sentry_init, immediate_backend, capture_events):
135135
with pytest.raises(ValueError, match="Task failed"):
136136
_ = result.return_value
137137

138-
assert len(events) >= 1
138+
assert len(events) == 2
139139
transaction_event = events[-1]
140140
assert transaction_event["type"] == "transaction"
141141

@@ -148,27 +148,6 @@ def test_task_error_reporting(sentry_init, immediate_backend, capture_events):
148148
assert queue_submit_spans[0]["description"] == "failing_task"
149149

150150

151-
@pytest.mark.skipif(
152-
not HAS_DJANGO_TASKS,
153-
reason="Django tasks are only available in Django 6.0+",
154-
)
155-
def test_task_span_not_created_without_integration(
156-
sentry_init, capture_events, immediate_backend
157-
):
158-
"""Test that no span is created when DjangoIntegration is not enabled."""
159-
sentry_init(traces_sample_rate=1.0, default_integrations=False)
160-
events = capture_events()
161-
162-
with sentry_sdk.start_transaction(name="test_transaction"):
163-
simple_task.enqueue()
164-
165-
(event,) = events
166-
queue_submit_spans = [
167-
span for span in event["spans"] if span["op"] == OP.QUEUE_SUBMIT_DJANGO
168-
]
169-
assert len(queue_submit_spans) == 0
170-
171-
172151
@pytest.mark.skipif(
173152
not HAS_DJANGO_TASKS,
174153
reason="Django tasks are only available in Django 6.0+",
@@ -197,32 +176,3 @@ def test_multiple_task_enqueues_create_multiple_spans(
197176
span_names = [span["description"] for span in queue_submit_spans]
198177
assert span_names.count("task_one") == 2
199178
assert span_names.count("task_two") == 1
200-
201-
202-
@pytest.mark.skipif(
203-
not HAS_DJANGO_TASKS,
204-
reason="Django tasks are only available in Django 6.0+",
205-
)
206-
def test_nested_task_enqueue_spans(sentry_init, capture_events, immediate_backend):
207-
"""Test that task spans are properly nested under parent spans."""
208-
sentry_init(
209-
integrations=[DjangoIntegration()],
210-
traces_sample_rate=1.0,
211-
)
212-
events = capture_events()
213-
214-
with sentry_sdk.start_transaction(name="test_transaction"):
215-
with start_span(op="custom.operation", name="parent_span"):
216-
simple_task.enqueue()
217-
218-
(event,) = events
219-
220-
custom_spans = [span for span in event["spans"] if span["op"] == "custom.operation"]
221-
queue_submit_spans = [
222-
span for span in event["spans"] if span["op"] == OP.QUEUE_SUBMIT_DJANGO
223-
]
224-
225-
assert len(custom_spans) == 1
226-
assert len(queue_submit_spans) == 1
227-
228-
assert queue_submit_spans[0]["parent_span_id"] == custom_spans[0]["span_id"]

0 commit comments

Comments
 (0)