Skip to content

Commit cf582f6

Browse files
authored
fix: Do not double sample transactions (#732)
Transactions should be sampled independent of error events. We should never "roll the dice" twice to decide when to send a transaction to Sentry.
1 parent 8aecc71 commit cf582f6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

sentry_sdk/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ def _should_capture(
237237
scope=None, # type: Optional[Scope]
238238
):
239239
# type: (...) -> bool
240+
if event.get("type") == "transaction":
241+
# Transactions are sampled independent of error events.
242+
return True
243+
240244
if scope is not None and not scope._should_capture:
241245
return False
242246

tests/test_tracing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,15 @@ 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+
160+
def test_no_double_sampling(sentry_init, capture_events):
161+
# Transactions should not be subject to the global/error sample rate.
162+
# Only the traces_sample_rate should apply.
163+
sentry_init(traces_sample_rate=1.0, sample_rate=0.0)
164+
events = capture_events()
165+
166+
with Hub.current.start_span(transaction="/"):
167+
pass
168+
169+
assert len(events) == 1

0 commit comments

Comments
 (0)