diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 036fc48340..a0ad68533c 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -237,6 +237,10 @@ def _should_capture( scope=None, # type: Optional[Scope] ): # type: (...) -> bool + if event.get("type") == "transaction": + # Transactions are sampled independent of error events. + return True + if scope is not None and not scope._should_capture: return False diff --git a/tests/test_tracing.py b/tests/test_tracing.py index d68f815bd2..98ab47feb8 100644 --- a/tests/test_tracing.py +++ b/tests/test_tracing.py @@ -155,3 +155,15 @@ def test_nested_span_sampling_override(): assert span.sampled is True with Hub.current.start_span(transaction="inner", sampled=False) as span: assert span.sampled is False + + +def test_no_double_sampling(sentry_init, capture_events): + # Transactions should not be subject to the global/error sample rate. + # Only the traces_sample_rate should apply. + sentry_init(traces_sample_rate=1.0, sample_rate=0.0) + events = capture_events() + + with Hub.current.start_span(transaction="/"): + pass + + assert len(events) == 1