Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
23 changes: 23 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading