Skip to content
Closed
2 changes: 1 addition & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/django/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
)

Expand Down
1 change: 1 addition & 0 deletions tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",),
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/opentelemetry/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions tests/integrations/wsgi/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions tests/test_dsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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)",
),
Expand All @@ -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"]:
Expand Down
8 changes: 6 additions & 2 deletions tests/tracing/test_sample_rand_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
49 changes: 39 additions & 10 deletions tests/tracing/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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
Expand All @@ -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"):
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test passes only if traces_sample_rate=None and it fails when it is 0 or 1.0. I am not sure if this is the excepted behavior.

traces_sampler=traces_sampler,
)
record_lost_event_calls = capture_record_lost_event_calls()

with start_span(name="dogpark") as span:
Expand Down
Loading