Skip to content

Commit 0eb003b

Browse files
committed
.
1 parent b8fefb2 commit 0eb003b

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

sentry_sdk/integrations/celery/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
353353
sentry_sdk.traces.continue_trace(headers)
354354
span = sentry_sdk.traces.start_span(
355355
name=task.name,
356+
parent_span=None, # make this a segment
356357
attributes={
357358
"sentry.origin": CeleryIntegration.origin,
358359
"sentry.span.source": TransactionSource.TASK.value,
@@ -552,9 +553,10 @@ def sentry_publish(self: "Producer", *args: "Any", **kwargs: "Any") -> "Any":
552553
# method will still work.
553554
kwargs_headers = {}
554555

555-
if "task" not in kwargs_headers:
556-
# filter out heartbeat and other internal Celery events
557-
return original_publish(self, *args, **kwargs)
556+
# XXX[ivana]: check whether this is needed with the parent checks
557+
# if "task" not in kwargs_headers:
558+
# # filter out heartbeat and other internal Celery events
559+
# return original_publish(self, *args, **kwargs)
558560

559561
task_name = kwargs_headers.get("task")
560562
task_id = kwargs_headers.get("id")

tests/integrations/celery/test_celery.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,14 @@ def dummy_task(x, y):
240240
assert error_event["contexts"]["trace"]["trace_id"] == span.trace_id
241241
assert error_event["exception"]["values"][0]["type"] == "ZeroDivisionError"
242242

243-
span_items = [item.payload for item in items]
244-
process_span, execution_span, submit_span, submission_span = span_items
243+
process_span, execution_span, submit_span, submission_span = [
244+
item.payload for item in items
245+
]
245246

246247
assert execution_span["name"] == "dummy_task"
248+
assert execution_span["is_segment"] is True
247249
assert execution_span["attributes"]["sentry.span.source"] == "task"
248250
assert execution_span["trace_id"] == span.trace_id
249-
250-
assert submit_span["name"] == "dummy_task"
251-
assert submit_span["trace_id"] == span.trace_id
252-
assert submit_span["attributes"]["sentry.origin"] == "auto.queue.celery"
253-
assert submit_span["parent_span_id"] == span.span_id
254-
255251
if task_fails:
256252
assert execution_span["status"] == "error"
257253
else:
@@ -260,6 +256,18 @@ def dummy_task(x, y):
260256
assert process_span["name"] == "dummy_task"
261257
assert process_span["trace_id"] == span.trace_id
262258
assert process_span["attributes"]["sentry.op"] == "queue.process"
259+
assert process_span["parent_span_id"] == execution_span["span_id"]
260+
261+
assert submission_span["name"] == "submission"
262+
assert submission_span["is_segment"] is True
263+
264+
assert submit_span["name"] == "dummy_task"
265+
assert submit_span["attributes"]["sentry.op"] == "queue.submit.celery"
266+
assert submit_span["attributes"]["sentry.origin"] == "auto.queue.celery"
267+
assert (
268+
submit_span["parent_span_id"] == submission_span["span_id"] == span.span_id
269+
)
270+
assert submit_span["trace_id"] == span.trace_id
263271

264272
else:
265273
events = capture_events()

0 commit comments

Comments
 (0)