From 278b7863c7774b4cc647ea2c1c71815584cdc7cd Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Tue, 25 Aug 2026 15:21:40 -0400 Subject: [PATCH 1/2] fix(dramatiq): Gate request body collection on data_collection experiment Only attach dramatiq message data to the event when the data_collection experiment's http_bodies config includes "incoming_request", matching the behavior in other integrations (e.g. aiohttp). The "dramatiq" context type is still always set. Refs PY-2419 Refs #6283 --- sentry_sdk/integrations/dramatiq.py | 20 ++++-- tests/integrations/dramatiq/test_dramatiq.py | 71 +++++++++++++++++++- 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/sentry_sdk/integrations/dramatiq.py b/sentry_sdk/integrations/dramatiq.py index 2840c24fe5..01ad4e1b28 100644 --- a/sentry_sdk/integrations/dramatiq.py +++ b/sentry_sdk/integrations/dramatiq.py @@ -17,6 +17,7 @@ AnnotatedValue, capture_internal_exceptions, event_from_exception, + has_data_collection_enabled, ) R = TypeVar("R") @@ -241,10 +242,17 @@ def extract_into_event(self, event: "Event") -> None: request_info = contexts.setdefault("dramatiq", {}) request_info["type"] = "dramatiq" - data: "Optional[Union[AnnotatedValue, Dict[str, Any]]]" = None - if not request_body_within_bounds(client, self.content_length()): - data = AnnotatedValue.removed_because_over_size_limit() - else: - data = self.message_data + attach_request_body = True + if has_data_collection_enabled(client.options): + attach_request_body = ( + "incoming_request" in client.options["data_collection"]["http_bodies"] + ) + + if attach_request_body: + data: "Optional[Union[AnnotatedValue, Dict[str, Any]]]" = None + if not request_body_within_bounds(client, self.content_length()): + data = AnnotatedValue.removed_because_over_size_limit() + else: + data = self.message_data - request_info["data"] = data + request_info["data"] = data diff --git a/tests/integrations/dramatiq/test_dramatiq.py b/tests/integrations/dramatiq/test_dramatiq.py index 45e3547ee0..a7a1e9fe7e 100644 --- a/tests/integrations/dramatiq/test_dramatiq.py +++ b/tests/integrations/dramatiq/test_dramatiq.py @@ -328,7 +328,7 @@ def dummy_actor(): sentry_sdk.capture_message("hi") dummy_actor.send() - broker.join(dummy_actor.queue_name) + broker.join(dummy_actor.queue_name, fail_fast=False) worker.join() (event,) = events @@ -455,6 +455,75 @@ def dummy_actor(x, y): assert isinstance(request_data["message_timestamp"], int) +@pytest.mark.parametrize( + "broker,expect_message_data", + [ + pytest.param({}, True, id="data_collection_not_enabled"), + pytest.param( + { + "_experiments": { + "data_collection": {"http_bodies": ["incoming_request"]} + } + }, + True, + id="data_collection_http_bodies_incoming_request", + ), + pytest.param( + {"_experiments": {"data_collection": {"http_bodies": []}}}, + False, + id="data_collection_http_bodies_empty", + ), + ], + indirect=["broker"], +) +def test_that_message_data_is_gated_by_data_collection( + broker, worker, capture_events, expect_message_data +): + events = capture_events() + + @dramatiq.actor(max_retries=0) + def dummy_actor(x, y): + return x / y + + dummy_actor.send_with_options(args=(1, 0), max_retries=0) + broker.join(dummy_actor.queue_name, fail_fast=False) + worker.join() + + (event,) = events + dramatiq_context = event["contexts"]["dramatiq"] + + if expect_message_data: + assert dramatiq_context["data"]["actor_name"] == "dummy_actor" + assert dramatiq_context["data"]["args"] == [1, 0] + else: + assert "data" not in dramatiq_context + + +@pytest.mark.parametrize( + "broker", + [{"_experiments": {"data_collection": {"http_bodies": []}}}], + indirect=True, +) +def test_that_dramatiq_context_type_is_set_regardless_of_data_collection( + broker, worker, capture_events +): + events = capture_events() + + @dramatiq.actor(max_retries=0) + def dummy_actor(x, y): + return x / y + + dummy_actor.send_with_options(args=(1, 0), max_retries=0) + broker.join(dummy_actor.queue_name, fail_fast=False) + worker.join() + + (event,) = events + dramatiq_context = event["contexts"]["dramatiq"] + + assert dramatiq_context["type"] == "dramatiq" + assert "data" not in dramatiq_context + + @pytest.mark.parametrize( "fail_fast", [ From f1bf9e99e97f92483f3a7f1a8b07463e512136be Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Tue, 25 Aug 2026 15:32:34 -0400 Subject: [PATCH 2/2] . --- tests/integrations/dramatiq/test_dramatiq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/dramatiq/test_dramatiq.py b/tests/integrations/dramatiq/test_dramatiq.py index a7a1e9fe7e..b5812ef247 100644 --- a/tests/integrations/dramatiq/test_dramatiq.py +++ b/tests/integrations/dramatiq/test_dramatiq.py @@ -328,7 +328,7 @@ def dummy_actor(): sentry_sdk.capture_message("hi") dummy_actor.send() - broker.join(dummy_actor.queue_name, fail_fast=False) + broker.join(dummy_actor.queue_name) worker.join() (event,) = events