Skip to content

Commit b74bc10

Browse files
feat(rq): Add messaging.destination.name attribute to consumer spans
1 parent e2dd162 commit b74bc10

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

sentry_sdk/integrations/rq.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def sentry_patched_perform_job(
9999
if func_name is not None:
100100
span.set_attribute(SPANDATA.CODE_FUNCTION_NAME, func_name)
101101

102+
if args:
103+
span.set_attribute(
104+
SPANDATA.MESSAGING_DESTINATION_NAME, args[0].name
105+
)
106+
102107
rv = old_perform_job(self, job, *args, **kwargs)
103108
else:
104109
transaction = continue_trace(
@@ -115,7 +120,12 @@ def sentry_patched_perform_job(
115120
with sentry_sdk.start_transaction(
116121
transaction,
117122
custom_sampling_context={"rq_job": job},
118-
):
123+
) as span:
124+
if args:
125+
span.set_data(
126+
SPANDATA.MESSAGING_DESTINATION_NAME, args[0].name
127+
)
128+
119129
rv = old_perform_job(self, job, *args, **kwargs)
120130

121131
if self.is_horse:

tests/integrations/rq/test_rq.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ def test_transaction_no_error(
416416

417417
assert span["attributes"]["sentry.op"] == "queue.task.rq"
418418
assert span["name"] == "tests.integrations.rq.test_rq.do_trick"
419+
assert span["attributes"][SPANDATA.MESSAGING_DESTINATION_NAME] == queue.name
419420
else:
420421
events = capture_events()
421422

@@ -427,6 +428,10 @@ def test_transaction_no_error(
427428
assert envelope["type"] == "transaction"
428429
assert envelope["contexts"]["trace"]["op"] == "queue.task.rq"
429430
assert envelope["transaction"] == "tests.integrations.rq.test_rq.do_trick"
431+
assert (
432+
envelope["contexts"]["trace"]["data"][SPANDATA.MESSAGING_DESTINATION_NAME]
433+
== queue.name
434+
)
430435
assert envelope["extra"]["rq-job"] == DictionaryContaining(
431436
{
432437
"args": ["Maisey"] if send_default_pii else SENSITIVE_DATA_SUBSTITUTE,

uv.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)