Skip to content

Commit cc8d812

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 8aecc71 commit cc8d812

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,14 @@ def test_nested_span_sampling_override():
155155
assert span.sampled is True
156156
with Hub.current.start_span(transaction="inner", sampled=False) as span:
157157
assert span.sampled is False
158+
159+
def test_transactions_do_not_go_through_before_send(sentry_init, capture_events):
160+
def before_send(event, hint):
161+
raise RuntimeError("should not be called")
162+
sentry_init(traces_sample_rate=1.0, before_send=before_send)
163+
events = capture_events()
164+
165+
with Hub.current.start_span(transaction="/"):
166+
pass
167+
168+
assert len(events) == 1

0 commit comments

Comments
 (0)