diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 40fc145558..98d98a72ae 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -551,7 +551,7 @@ def __init__( debug=None, # type: Optional[bool] attach_stacktrace=False, # type: bool ca_certs=None, # type: Optional[str] - traces_sample_rate=0, # type: Optional[float] + traces_sample_rate=None, # type: Optional[float] traces_sampler=None, # type: Optional[TracesSampler] profiles_sample_rate=None, # type: Optional[float] profiles_sampler=None, # type: Optional[TracesSampler] diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 8e0c74f365..bc019d54a4 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -461,10 +461,7 @@ async def hello(request): async def test_trace_from_headers_if_performance_disabled( sentry_init, aiohttp_client, capture_events ): - sentry_init( - integrations=[AioHttpIntegration()], - traces_sample_rate=None, # disable all performance monitoring - ) + sentry_init(integrations=[AioHttpIntegration()]) async def hello(request): capture_message("It's a good day to try dividing by 0") diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index f14e960fff..9e97ae3651 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -269,9 +269,7 @@ async def test_has_trace_if_performance_disabled( asgi3_app_with_error_and_msg, capture_events, ): - sentry_init( - traces_sample_rate=None, # disable all performance monitoring - ) + sentry_init() app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg) with pytest.raises(ZeroDivisionError): @@ -327,9 +325,7 @@ async def test_trace_from_headers_if_performance_disabled( asgi3_app_with_error_and_msg, capture_events, ): - sentry_init( - traces_sample_rate=None, # disable all performance monitoring - ) + sentry_init() app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg) trace_id = "582b43a4192642f0b136d5159a501701" diff --git a/tests/integrations/django/asgi/test_asgi.py b/tests/integrations/django/asgi/test_asgi.py index 3a5e47cfa8..c10a6b7b8e 100644 --- a/tests/integrations/django/asgi/test_asgi.py +++ b/tests/integrations/django/asgi/test_asgi.py @@ -335,10 +335,7 @@ async def test_has_trace_if_performance_enabled(sentry_init, capture_events): django.VERSION < (3, 1), reason="async views have been introduced in Django 3.1" ) async def test_has_trace_if_performance_disabled(sentry_init, capture_events): - sentry_init( - integrations=[DjangoIntegration()], - traces_sample_rate=None, # disable all performance monitoring - ) + sentry_init(integrations=[DjangoIntegration()]) events = capture_events() @@ -401,10 +398,7 @@ async def test_trace_from_headers_if_performance_enabled(sentry_init, capture_ev django.VERSION < (3, 1), reason="async views have been introduced in Django 3.1" ) async def test_trace_from_headers_if_performance_disabled(sentry_init, capture_events): - sentry_init( - integrations=[DjangoIntegration()], - traces_sample_rate=None, # disable all performance monitoring - ) + sentry_init(integrations=[DjangoIntegration()]) events = capture_events() diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index a37576315f..5b75bbb6af 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -241,7 +241,6 @@ def test_trace_from_headers_if_performance_disabled( http_methods_to_capture=("HEAD",), ) ], - traces_sample_rate=None, # disable all performance monitoring ) events = capture_events() diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index 149dd1d7d4..76c80f6c6a 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -238,9 +238,7 @@ def dogpark(environ, start_response): capture_message("Attempting to fetch the ball") raise ValueError("Fetch aborted. The ball was not returned.") - sentry_init( - traces_sample_rate=None, # disable all performance monitoring - ) + sentry_init() app = SentryWsgiMiddleware(dogpark) client = Client(app) events = capture_events() @@ -303,9 +301,7 @@ def dogpark(environ, start_response): capture_message("Attempting to fetch the ball") raise ValueError("Fetch aborted. The ball was not returned.") - sentry_init( - traces_sample_rate=None, # disable all performance monitoring - ) + sentry_init() app = SentryWsgiMiddleware(dogpark) client = Client(app) events = capture_events() diff --git a/tests/opentelemetry/test_sampler.py b/tests/opentelemetry/test_sampler.py index 7198f6b390..4ca1e1963f 100644 --- a/tests/opentelemetry/test_sampler.py +++ b/tests/opentelemetry/test_sampler.py @@ -178,8 +178,8 @@ def keep_only_a(sampling_context): @pytest.mark.parametrize( "traces_sample_rate, expected_num_of_envelopes", [ - # special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used) - (USE_DEFAULT_TRACES_SAMPLE_RATE, 1), + # special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used) + (USE_DEFAULT_TRACES_SAMPLE_RATE, 0), # traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all. (None, 0), # traces_sample_rate=0 means do not create new traces (0% of the requests), but continue incoming traces. So envelopes will be created only if there is an incoming trace. @@ -229,9 +229,9 @@ def test_sampling_parent_sampled( @pytest.mark.parametrize( "traces_sample_rate, upstream_sampled, expected_num_of_envelopes", [ - # special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used) + # special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used) (USE_DEFAULT_TRACES_SAMPLE_RATE, 0, 0), - (USE_DEFAULT_TRACES_SAMPLE_RATE, 1, 1), + (USE_DEFAULT_TRACES_SAMPLE_RATE, 1, 0), # traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all. (None, 0, 0), (None, 1, 0), diff --git a/tests/test_dsc.py b/tests/test_dsc.py index 569b7fd3dc..ea3c0b8988 100644 --- a/tests/test_dsc.py +++ b/tests/test_dsc.py @@ -287,8 +287,8 @@ def my_traces_sampler(sampling_context): "local_traces_sampler_result": None, "local_traces_sample_rate": None, }, - 1.0, # expected_sample_rate - "true", # expected_sampled + None, # expected_sample_rate + "tracing-disabled-no-transactions-should-be-sent", # expected_sampled (traces_sample_rate=None disables all transaction creation) ), ( # 6 traces_sampler overrides incoming (traces_sample_rate not set) { diff --git a/tests/tracing/test_trace_propagation.py b/tests/tracing/test_trace_propagation.py index cb4c3fc90d..358e3f48aa 100644 --- a/tests/tracing/test_trace_propagation.py +++ b/tests/tracing/test_trace_propagation.py @@ -190,7 +190,11 @@ def test_with_incoming_trace_and_trace_propagation_targets_matching( requests.get("http://example.com") # CHECK if performance data (a transaction/span) is sent to Sentry - if traces_sample_rate is None or incoming_parent_sampled == "0": + if ( + traces_sample_rate is None + or traces_sample_rate == USE_DEFAULT_TRACES_SAMPLE_RATE + or incoming_parent_sampled == "0" + ): assert len(events) == 0 else: if incoming_parent_sampled == "1" or traces_sample_rate == 1: @@ -264,7 +268,11 @@ def test_with_incoming_trace_and_trace_propagation_targets_not_matching( requests.get("http://example.com") # CHECK if performance data (a transaction/span) is sent to Sentry - if traces_sample_rate is None or incoming_parent_sampled == "0": + if ( + traces_sample_rate is None + or traces_sample_rate == USE_DEFAULT_TRACES_SAMPLE_RATE + or incoming_parent_sampled == "0" + ): assert len(events) == 0 else: if incoming_parent_sampled == "1" or traces_sample_rate == 1: