Skip to content

Commit 82c5a05

Browse files
committed
fix: Do not call before_send for transactions
This matches the behavior with JS and the specs in https://develop.sentry.dev/sdk/unified-api/tracing
1 parent cf582f6 commit 82c5a05

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sentry_sdk/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _prepare_event(
199199
event = serialize(event)
200200

201201
before_send = self.options["before_send"]
202-
if before_send is not None:
202+
if before_send is not None and event.get("type") != "transaction":
203203
new_event = None
204204
with capture_internal_exceptions():
205205
new_event = before_send(event, hint or {})

tests/test_tracing.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,16 @@ def test_no_double_sampling(sentry_init, capture_events):
167167
pass
168168

169169
assert len(events) == 1
170+
171+
172+
def test_transactions_do_not_go_through_before_send(sentry_init, capture_events):
173+
def before_send(event, hint):
174+
raise RuntimeError("should not be called")
175+
176+
sentry_init(traces_sample_rate=1.0, before_send=before_send)
177+
events = capture_events()
178+
179+
with Hub.current.start_span(transaction="/"):
180+
pass
181+
182+
assert len(events) == 1

0 commit comments

Comments
 (0)