Skip to content

Commit 39e3a50

Browse files
author
igorek
committed
feat(integrations): Start new trace on retrying
- Start new trace in case of retrying task. Such decision makes life easier to investigate failed transactions in complicated traces. - also fix logging issue in tests Issue: #3454
1 parent 7156ac4 commit 39e3a50

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

sentry_sdk/integrations/dramatiq.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,13 @@ def before_process_message(self, broker, message):
127127
scope.clear_breadcrumbs()
128128
scope.add_event_processor(_make_message_event_processor(message, integration))
129129

130+
sentry_headers = message.options.get("sentry_headers") or {}
131+
if "retries" in message.options:
132+
# start new trace in case of retrying
133+
sentry_headers = {}
134+
130135
transaction = continue_trace(
131-
message.options.get("sentry_headers") or {},
136+
sentry_headers,
132137
name=message.actor_name,
133138
op=OP.QUEUE_TASK_DRAMATIQ,
134139
source=TransactionSource.TASK,

tests/integrations/dramatiq/test_dramatiq.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
from sentry_sdk import start_transaction
1010
from sentry_sdk.consts import SPANSTATUS
1111
from sentry_sdk.integrations.dramatiq import DramatiqIntegration
12+
from sentry_sdk.integrations.logging import ignore_logger
1213

13-
# from sentry_sdk.integrations.logging import LoggingIntegration
14+
ignore_logger("dramatiq.worker.WorkerThread")
1415

1516

1617
@pytest.fixture(scope="function")
1718
def broker(request, sentry_init):
1819
sentry_init(
1920
integrations=[DramatiqIntegration()],
2021
traces_sample_rate=getattr(request, "param", None),
21-
# disabled_integrations=[LoggingIntegration()],
2222
)
2323
broker = StubBroker()
2424
broker.emit_after("process_boot")
@@ -78,8 +78,7 @@ def dummy_actor(x, y):
7878
error_event = events.pop(0)
7979
exception = error_event["exception"]["values"][0]
8080
assert exception["type"] == "ZeroDivisionError"
81-
# todo: failed assert. Logging instead of dramatiq
82-
# assert exception["mechanism"]["type"] == DramatiqIntegration.identifier
81+
assert exception["mechanism"]["type"] == DramatiqIntegration.identifier
8382

8483
(event,) = events
8584
assert event["type"] == "transaction"

0 commit comments

Comments
 (0)