Skip to content

Commit beb6501

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

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

sentry_sdk/integrations/dramatiq.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import sentry_sdk
55
from sentry_sdk.api import continue_trace, get_baggage, get_traceparent
6-
from sentry_sdk.consts import OP, SPANSTATUS
6+
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
77
from sentry_sdk.integrations import DidNotEnable, Integration
88
from sentry_sdk.integrations._wsgi_common import request_body_within_bounds
99
from sentry_sdk.traces import SegmentSource
@@ -140,6 +140,7 @@ def before_process_message(self, broker: "Broker", message: "Message[R]") -> Non
140140
"sentry.op": OP.QUEUE_TASK_DRAMATIQ,
141141
"sentry.origin": DramatiqIntegration.origin,
142142
"sentry.span.source": SegmentSource.TASK.value,
143+
SPANDATA.MESSAGING_DESTINATION_NAME: message.queue_name,
143144
},
144145
parent_span=None,
145146
)
@@ -160,6 +161,9 @@ def before_process_message(self, broker: "Broker", message: "Message[R]") -> Non
160161
source=TransactionSource.TASK,
161162
)
162163
transaction.__enter__()
164+
transaction.set_data(
165+
SPANDATA.MESSAGING_DESTINATION_NAME, message.queue_name
166+
)
163167
message._sentry_span_ctx = transaction
164168

165169
def after_process_message(

tests/integrations/dramatiq/test_dramatiq.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import sentry_sdk
99
from sentry_sdk import start_transaction
10-
from sentry_sdk.consts import SPANSTATUS
10+
from sentry_sdk.consts import SPANDATA, SPANSTATUS
1111
from sentry_sdk.integrations.dramatiq import DramatiqIntegration
1212
from sentry_sdk.integrations.logging import ignore_logger
1313
from sentry_sdk.tracing import Transaction, TransactionSource
@@ -172,6 +172,10 @@ def dummy_actor(x, y):
172172
assert segment["is_segment"] is True
173173
assert segment["attributes"]["sentry.op"] == "queue.task.dramatiq"
174174
assert segment["attributes"]["sentry.span.source"] == "task"
175+
assert (
176+
segment["attributes"][SPANDATA.MESSAGING_DESTINATION_NAME]
177+
== dummy_actor.queue_name
178+
)
175179
assert segment["status"] == ("error" if task_fails else "ok")
176180
else:
177181
if task_fails:
@@ -184,6 +188,10 @@ def dummy_actor(x, y):
184188
assert event["type"] == "transaction"
185189
assert event["transaction"] == "dummy_actor"
186190
assert event["transaction_info"] == {"source": TransactionSource.TASK}
191+
assert (
192+
event["contexts"]["trace"]["data"][SPANDATA.MESSAGING_DESTINATION_NAME]
193+
== dummy_actor.queue_name
194+
)
187195
assert event["contexts"]["trace"]["status"] == expected_span_status
188196

189197

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)