diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 16bb8ac02b..ecd70e7912 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -393,6 +393,18 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]": stacklevel=2, ) + # The SDK logger only writes when debug is on, and this has to reach people who + # never turn it on. + if rv["traces_sample_rate"] == 0 and rv["traces_sampler"] is None: + warnings.warn( + "traces_sample_rate is 0, so this service starts no traces and Sentry " + "gets no performance data from it. To send traces, set traces_sample_rate " + "above 0, for example 1.0 in development and 0.1 in production. If 0 is " + "what you want (for example, to only continue traces sampled upstream), " + "you can hide this warning with warnings.filterwarnings.", + stacklevel=2, + ) + if rv["trace_ignore_status_codes"] and has_span_streaming_enabled(rv): warnings.warn( "The `trace_ignore_status_codes` parameter is ignored in span streaming mode.", diff --git a/tests/test_client.py b/tests/test_client.py index 7dc3922285..5cf008eafe 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1507,6 +1507,29 @@ def test_continuous_profiling_does_not_warn(sentry_init): assert profiling_warnings == [] +@pytest.mark.parametrize("traces_sample_rate", [0, 0.0]) +def test_zero_traces_sample_rate_warns(sentry_init, traces_sample_rate): + with pytest.warns(UserWarning, match="traces_sample_rate is 0"): + sentry_init(traces_sample_rate=traces_sample_rate) + + +@pytest.mark.parametrize( + "options", + [ + {"traces_sample_rate": 0, "traces_sampler": lambda _: 1.0}, + {"traces_sample_rate": 0.1}, + {"traces_sample_rate": None}, + {}, + ], +) +def test_zero_traces_sample_rate_does_not_warn(sentry_init, options): + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + sentry_init(**options) + + assert [w for w in caught if "traces_sample_rate is 0" in str(w.message)] == [] + + def test_ignore_spans_warns_without_streaming(sentry_init): with pytest.warns(UserWarning, match=r"`ignore_spans` parameter only works"): sentry_init(ignore_spans=["/health"], trace_lifecycle="static")