Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ async def _sentry_run_job(self: "Worker", job_id: str, score: int) -> None:
SPANDATA.MESSAGING_MESSAGE_ID: job_id,
},
parent_span=None,
):
) as span:
if self.queue_name is not None:
span.set_attribute(
SPANDATA.MESSAGING_DESTINATION_NAME, self.queue_name
)
return await old_run_job(self, job_id, score)

transaction = Transaction(
Expand All @@ -130,7 +134,9 @@ async def _sentry_run_job(self: "Worker", job_id: str, score: int) -> None:
origin=ArqIntegration.origin,
)

with sentry_sdk.start_transaction(transaction):
with sentry_sdk.start_transaction(transaction) as span:
if self.queue_name is not None:
span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, self.queue_name)
return await old_run_job(self, job_id, score)

Worker.run_job = _sentry_run_job
Expand Down
9 changes: 9 additions & 0 deletions tests/integrations/arq/test_arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import sentry_sdk
from sentry_sdk import get_client, start_transaction
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations.arq import ArqIntegration


Expand Down Expand Up @@ -364,6 +365,10 @@ async def division(_, a, b=0):

division_span = next(span for span in task_spans if span["name"] == "division")
assert division_span["attributes"]["sentry.span.source"] == "task"
assert (
division_span["attributes"][SPANDATA.MESSAGING_DESTINATION_NAME]
== worker.queue_name
)

assert any(span["name"] == "cron:division" for span in task_spans)
else:
Expand Down Expand Up @@ -410,6 +415,10 @@ async def division(_, a, b=0):
assert func_event["type"] == "transaction"
assert func_event["transaction"] == "division"
assert func_event["transaction_info"] == {"source": "task"}
assert (
func_event["contexts"]["trace"]["data"][SPANDATA.MESSAGING_DESTINATION_NAME]
== worker.queue_name
)

assert "arq_task_id" in func_event["tags"]
assert "arq_task_retry" in func_event["tags"]
Expand Down
Loading