From 84120affcdd8b9a973c6f608afe31ae31cba7aa8 Mon Sep 17 00:00:00 2001 From: Dan Fuller Date: Fri, 13 Nov 2026 15:49:34 -0800 Subject: [PATCH] feat(tracing): Warn when traces_sample_rate is 0 A lot of new setups, many of them written by AI coding agents, configure tracing but set traces_sample_rate to 0, often through a setting or environment variable that defaults to 0 and is never set. The SDK then instruments every request, starts no traces and sends no performance data, and nothing tells anyone. Most of these setups stay that way. Warn at init when traces_sample_rate is 0 and no traces_sampler is set. It uses warnings.warn rather than the SDK logger, because the logger only writes when debug is on. The message says how to send traces, and that the warning can be hidden with warnings.filterwarnings when 0 is intentional (for example, to only continue traces sampled upstream). There's no warning when traces_sample_rate isn't set, is None, or is above 0, or when a traces_sampler is set. Co-Authored-By: Claude Opus 5.5 --- sentry_sdk/client.py | 12 ++++++++++++ tests/test_client.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) 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")