diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 50d08f948e..a49cb3a680 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -511,7 +511,7 @@ def __init__( debug=None, # type: Optional[bool] attach_stacktrace=False, # type: bool ca_certs=None, # type: Optional[str] - traces_sample_rate=None, # type: Optional[float] + traces_sample_rate=0, # 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/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 010f2a3d2a..e856d7ef3e 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -678,6 +678,12 @@ def set_tag(self, key, value): def set_data(self, key, value): # type: (str, Any) -> None + warnings.warn( + "`Span.set_data` is deprecated. Please use `Span.set_attribute` instead.", + DeprecationWarning, + stacklevel=2, + ) + # TODO-neel-potel we cannot add dicts here self.set_attribute(key, value) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 93560421c0..c21400396a 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -448,7 +448,10 @@ async def hello(request): async def test_trace_from_headers_if_performance_disabled( sentry_init, aiohttp_client, capture_events ): - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init( + traces_sample_rate=None, # disable all performance monitoring + 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 d0ddef8611..0f1f22b67a 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -325,7 +325,9 @@ async def test_trace_from_headers_if_performance_disabled( asgi3_app_with_error_and_msg, capture_events, ): - sentry_init() + sentry_init( + traces_sample_rate=None, # disable all performance monitoring + ) 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 f083447ed2..271e08680b 100644 --- a/tests/integrations/django/asgi/test_asgi.py +++ b/tests/integrations/django/asgi/test_asgi.py @@ -385,6 +385,7 @@ async def test_trace_from_headers_if_performance_enabled(sentry_init, capture_ev ) async def test_trace_from_headers_if_performance_disabled(sentry_init, capture_events): sentry_init( + traces_sample_rate=None, # disable all performance monitoring integrations=[DjangoIntegration()], ) diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index 5b75bbb6af..625ff022a9 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -236,6 +236,7 @@ def test_trace_from_headers_if_performance_disabled( sentry_init, client, capture_events ): sentry_init( + traces_sample_rate=None, # disable all performance monitoring integrations=[ DjangoIntegration( http_methods_to_capture=("HEAD",), diff --git a/tests/integrations/opentelemetry/test_sampler.py b/tests/integrations/opentelemetry/test_sampler.py index 8cccab05be..5ab4e8885f 100644 --- a/tests/integrations/opentelemetry/test_sampler.py +++ b/tests/integrations/opentelemetry/test_sampler.py @@ -176,8 +176,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=None will be used) - (-1, 0), + # special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used) + (-1, 1), # 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. diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index 76c80f6c6a..6015f3ba93 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -238,7 +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() + sentry_init(traces_sample_rate=None) app = SentryWsgiMiddleware(dogpark) client = Client(app) events = capture_events() @@ -301,7 +301,9 @@ def dogpark(environ, start_response): capture_message("Attempting to fetch the ball") raise ValueError("Fetch aborted. The ball was not returned.") - sentry_init() + sentry_init( + traces_sample_rate=None, # disable all performance monitoring + ) app = SentryWsgiMiddleware(dogpark) client = Client(app) events = capture_events() diff --git a/tests/test_dsc.py b/tests/test_dsc.py index ea3c0b8988..b267dd16d1 100644 --- a/tests/test_dsc.py +++ b/tests/test_dsc.py @@ -229,7 +229,7 @@ def my_traces_sampler(sampling_context): # "local_traces_sampler_result": # The result of the local traces sampler. # "local_traces_sample_rate": - # The `traces_sample_rate` setting in the local `sentry_init` call. + # The `traces_sample_rate` setting in the local `sentry_init` call. If -1, then it will not be set and the default traces_sample_rate will be used. ( # 1 traces_sample_rate does not override incoming { "incoming_sample_rate": 1.0, @@ -278,7 +278,7 @@ def my_traces_sampler(sampling_context): 0.25, # expected_sample_rate "false", # expected_sampled (traces sampler can override parent sampled) ), - ( # 5 forwarding incoming (traces_sample_rate not set) + ( # 5 not forwarding incoming (traces_sample_rate set to None) { "incoming_sample_rate": 1.0, "incoming_sampled": "true", @@ -297,12 +297,12 @@ def my_traces_sampler(sampling_context): "sentry_trace_header_parent_sampled": 1, "use_local_traces_sampler": True, "local_traces_sampler_result": 0.5, - "local_traces_sample_rate": None, + "local_traces_sample_rate": -1, }, 0.5, # expected_sample_rate "true", # expected_sampled (traces sampler overrides the traces_sample_rate setting, so transactions are created) ), - ( # 7 forwarding incoming (traces_sample_rate not set) (incoming not sampled) + ( # 7 not forwarding incoming (traces_sample_rate set to None) (incoming not sampled) { "incoming_sample_rate": 1.0, "incoming_sampled": "false", @@ -321,7 +321,7 @@ def my_traces_sampler(sampling_context): "sentry_trace_header_parent_sampled": 0, "use_local_traces_sampler": True, "local_traces_sampler_result": 0.25, - "local_traces_sample_rate": None, + "local_traces_sample_rate": -1, }, 0.25, # expected_sample_rate "false", # expected_sampled @@ -344,9 +344,9 @@ def my_traces_sampler(sampling_context): "2 traces_sampler overrides incoming", "3 traces_sample_rate does not overrides incoming sample rate or parent (incoming not sampled)", "4 traces_sampler overrides incoming (incoming not sampled)", - "5 forwarding incoming (traces_sample_rate not set)", + "5 not forwarding incoming (traces_sample_rate set to None)", "6 traces_sampler overrides incoming (traces_sample_rate not set)", - "7 forwarding incoming (traces_sample_rate not set) (incoming not sampled)", + "7 not forwarding incoming (traces_sample_rate set to None) (incoming not sampled)", "8 traces_sampler overrides incoming (traces_sample_rate not set) (incoming not sampled)", "9 traces_sample_rate overrides incoming (upstream deferred sampling decision)", ), @@ -373,7 +373,7 @@ def my_traces_sampler(sampling_context): "environment": "canary", } - if test_data["local_traces_sample_rate"]: + if test_data["local_traces_sample_rate"] != -1: init_kwargs["traces_sample_rate"] = test_data["local_traces_sample_rate"] if test_data["use_local_traces_sampler"]: diff --git a/tests/tracing/test_sample_rand_propagation.py b/tests/tracing/test_sample_rand_propagation.py index f598b24154..570a386e9e 100644 --- a/tests/tracing/test_sample_rand_propagation.py +++ b/tests/tracing/test_sample_rand_propagation.py @@ -15,7 +15,9 @@ def test_continue_trace_with_sample_rand(sentry_init): """ Test that an incoming sample_rand is propagated onto the transaction's baggage. """ - sentry_init() + sentry_init( + traces_sample_rate=None, + ) headers = { "sentry-trace": "00000000000000000000000000000000-0000000000000000-0", @@ -31,7 +33,9 @@ def test_continue_trace_missing_sample_rand(sentry_init): """ Test that a missing sample_rand is filled in onto the transaction's baggage. """ - sentry_init() + sentry_init( + traces_sample_rate=None, + ) headers = { "sentry-trace": "00000000000000000000000000000000-0000000000000000", diff --git a/tests/tracing/test_sampling.py b/tests/tracing/test_sampling.py index 59780729b7..0e764cade6 100644 --- a/tests/tracing/test_sampling.py +++ b/tests/tracing/test_sampling.py @@ -78,7 +78,10 @@ def test_uses_traces_sampler_return_value_correctly( traces_sampler_return_value, expected_decision, ): - sentry_init(traces_sampler=mock.Mock(return_value=traces_sampler_return_value)) + sentry_init( + traces_sample_rate=1.0, + traces_sampler=mock.Mock(return_value=traces_sampler_return_value), + ) with sentry_sdk.continue_trace( { @@ -94,7 +97,10 @@ def test_uses_traces_sampler_return_value_correctly( def test_tolerates_traces_sampler_returning_a_boolean( sentry_init, traces_sampler_return_value ): - sentry_init(traces_sampler=mock.Mock(return_value=traces_sampler_return_value)) + sentry_init( + traces_sample_rate=1.0, + traces_sampler=mock.Mock(return_value=traces_sampler_return_value), + ) with start_span(name="dogpark") as span: assert span.sampled is traces_sampler_return_value @@ -104,7 +110,10 @@ def test_tolerates_traces_sampler_returning_a_boolean( def test_only_captures_transaction_when_sampled_is_true( sentry_init, sampling_decision, capture_events ): - sentry_init(traces_sampler=mock.Mock(return_value=sampling_decision)) + sentry_init( + traces_sample_rate=1.0, + traces_sampler=mock.Mock(return_value=sampling_decision), + ) events = capture_events() with start_span(name="dogpark"): @@ -141,7 +150,10 @@ def test_ignores_inherited_sample_decision_when_traces_sampler_defined( # make traces_sampler pick the opposite of the inherited decision, to prove # that traces_sampler takes precedence traces_sampler = mock.Mock(return_value=not parent_sampling_decision) - sentry_init(traces_sampler=traces_sampler) + sentry_init( + traces_sample_rate=1.0, + traces_sampler=traces_sampler, + ) sentry_trace_header = ( "12312012123120121231201212312012-1121201211212012-{sampled}".format( @@ -163,7 +175,10 @@ def test_traces_sampler_doesnt_overwrite_explicitly_passed_sampling_decision( # make traces_sampler pick the opposite of the explicit decision, to prove # that the explicit decision takes precedence traces_sampler = mock.Mock(return_value=not explicit_decision) - sentry_init(traces_sampler=traces_sampler) + sentry_init( + traces_sample_rate=1.0, + traces_sampler=traces_sampler, + ) with start_span(name="dogpark", sampled=explicit_decision) as span: assert span.sampled is explicit_decision @@ -215,7 +230,7 @@ def test_passes_attributes_from_start_span_to_traces_sampler( sentry_init, DictionaryContaining # noqa: N803 ): traces_sampler = mock.Mock() - sentry_init(traces_sampler=traces_sampler) + sentry_init(traces_sample_rate=1.0, traces_sampler=traces_sampler) with start_span(attributes={"dogs": "yes", "cats": "maybe"}): traces_sampler.assert_any_call( @@ -252,7 +267,10 @@ def test_sample_rate_affects_errors(sentry_init, capture_events): def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value( sentry_init, traces_sampler_return_value, StringContaining # noqa: N803 ): - sentry_init(traces_sampler=mock.Mock(return_value=traces_sampler_return_value)) + sentry_init( + traces_sample_rate=None, + traces_sampler=mock.Mock(return_value=traces_sampler_return_value), + ) with mock.patch.object(logger, "warning", mock.Mock()): with start_span(name="dogpark") as span: @@ -294,13 +312,21 @@ def test_records_lost_event_only_if_traces_sample_rate_enabled( @pytest.mark.parametrize( "traces_sampler,sampled_output,expected_record_lost_event_calls", [ - (None, False, []), + ( + None, + False, + [], + ), ( lambda _x: 0.0, False, [("sample_rate", "transaction", None, 1), ("sample_rate", "span", None, 1)], ), - (lambda _x: 1.0, True, []), + ( + lambda _x: 1.0, + True, + [], + ), ], ) def test_records_lost_event_only_if_traces_sampler_enabled( @@ -310,7 +336,10 @@ def test_records_lost_event_only_if_traces_sampler_enabled( sampled_output, expected_record_lost_event_calls, ): - sentry_init(traces_sampler=traces_sampler) + sentry_init( + traces_sample_rate=None, + traces_sampler=traces_sampler, + ) record_lost_event_calls = capture_record_lost_event_calls() with start_span(name="dogpark") as span: