Skip to content

Commit 35fab6b

Browse files
authored
Traces sample rate default change (#4335)
Revert changing the default of `traces_sample_rate` done in #4240
1 parent a5d0f01 commit 35fab6b

File tree

9 files changed

+24
-34
lines changed

9 files changed

+24
-34
lines changed

sentry_sdk/consts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def __init__(
551551
debug=None, # type: Optional[bool]
552552
attach_stacktrace=False, # type: bool
553553
ca_certs=None, # type: Optional[str]
554-
traces_sample_rate=0, # type: Optional[float]
554+
traces_sample_rate=None, # type: Optional[float]
555555
traces_sampler=None, # type: Optional[TracesSampler]
556556
profiles_sample_rate=None, # type: Optional[float]
557557
profiles_sampler=None, # type: Optional[TracesSampler]

tests/integrations/aiohttp/test_aiohttp.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,7 @@ async def hello(request):
461461
async def test_trace_from_headers_if_performance_disabled(
462462
sentry_init, aiohttp_client, capture_events
463463
):
464-
sentry_init(
465-
integrations=[AioHttpIntegration()],
466-
traces_sample_rate=None, # disable all performance monitoring
467-
)
464+
sentry_init(integrations=[AioHttpIntegration()])
468465

469466
async def hello(request):
470467
capture_message("It's a good day to try dividing by 0")

tests/integrations/asgi/test_asgi.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ async def test_has_trace_if_performance_disabled(
269269
asgi3_app_with_error_and_msg,
270270
capture_events,
271271
):
272-
sentry_init(
273-
traces_sample_rate=None, # disable all performance monitoring
274-
)
272+
sentry_init()
275273
app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg)
276274

277275
with pytest.raises(ZeroDivisionError):
@@ -327,9 +325,7 @@ async def test_trace_from_headers_if_performance_disabled(
327325
asgi3_app_with_error_and_msg,
328326
capture_events,
329327
):
330-
sentry_init(
331-
traces_sample_rate=None, # disable all performance monitoring
332-
)
328+
sentry_init()
333329
app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg)
334330

335331
trace_id = "582b43a4192642f0b136d5159a501701"

tests/integrations/django/asgi/test_asgi.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,7 @@ async def test_has_trace_if_performance_enabled(sentry_init, capture_events):
335335
django.VERSION < (3, 1), reason="async views have been introduced in Django 3.1"
336336
)
337337
async def test_has_trace_if_performance_disabled(sentry_init, capture_events):
338-
sentry_init(
339-
integrations=[DjangoIntegration()],
340-
traces_sample_rate=None, # disable all performance monitoring
341-
)
338+
sentry_init(integrations=[DjangoIntegration()])
342339

343340
events = capture_events()
344341

@@ -401,10 +398,7 @@ async def test_trace_from_headers_if_performance_enabled(sentry_init, capture_ev
401398
django.VERSION < (3, 1), reason="async views have been introduced in Django 3.1"
402399
)
403400
async def test_trace_from_headers_if_performance_disabled(sentry_init, capture_events):
404-
sentry_init(
405-
integrations=[DjangoIntegration()],
406-
traces_sample_rate=None, # disable all performance monitoring
407-
)
401+
sentry_init(integrations=[DjangoIntegration()])
408402

409403
events = capture_events()
410404

tests/integrations/django/test_basic.py

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ def test_trace_from_headers_if_performance_disabled(
241241
http_methods_to_capture=("HEAD",),
242242
)
243243
],
244-
traces_sample_rate=None, # disable all performance monitoring
245244
)
246245

247246
events = capture_events()

tests/integrations/wsgi/test_wsgi.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ def dogpark(environ, start_response):
238238
capture_message("Attempting to fetch the ball")
239239
raise ValueError("Fetch aborted. The ball was not returned.")
240240

241-
sentry_init(
242-
traces_sample_rate=None, # disable all performance monitoring
243-
)
241+
sentry_init()
244242
app = SentryWsgiMiddleware(dogpark)
245243
client = Client(app)
246244
events = capture_events()
@@ -303,9 +301,7 @@ def dogpark(environ, start_response):
303301
capture_message("Attempting to fetch the ball")
304302
raise ValueError("Fetch aborted. The ball was not returned.")
305303

306-
sentry_init(
307-
traces_sample_rate=None, # disable all performance monitoring
308-
)
304+
sentry_init()
309305
app = SentryWsgiMiddleware(dogpark)
310306
client = Client(app)
311307
events = capture_events()

tests/opentelemetry/test_sampler.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ def keep_only_a(sampling_context):
178178
@pytest.mark.parametrize(
179179
"traces_sample_rate, expected_num_of_envelopes",
180180
[
181-
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used)
182-
(USE_DEFAULT_TRACES_SAMPLE_RATE, 1),
181+
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used)
182+
(USE_DEFAULT_TRACES_SAMPLE_RATE, 0),
183183
# traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all.
184184
(None, 0),
185185
# 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.
@@ -229,9 +229,9 @@ def test_sampling_parent_sampled(
229229
@pytest.mark.parametrize(
230230
"traces_sample_rate, upstream_sampled, expected_num_of_envelopes",
231231
[
232-
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used)
232+
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used)
233233
(USE_DEFAULT_TRACES_SAMPLE_RATE, 0, 0),
234-
(USE_DEFAULT_TRACES_SAMPLE_RATE, 1, 1),
234+
(USE_DEFAULT_TRACES_SAMPLE_RATE, 1, 0),
235235
# traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all.
236236
(None, 0, 0),
237237
(None, 1, 0),

tests/test_dsc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ def my_traces_sampler(sampling_context):
287287
"local_traces_sampler_result": None,
288288
"local_traces_sample_rate": None,
289289
},
290-
1.0, # expected_sample_rate
291-
"true", # expected_sampled
290+
None, # expected_sample_rate
291+
"tracing-disabled-no-transactions-should-be-sent", # expected_sampled (traces_sample_rate=None disables all transaction creation)
292292
),
293293
( # 6 traces_sampler overrides incoming (traces_sample_rate not set)
294294
{

tests/tracing/test_trace_propagation.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ def test_with_incoming_trace_and_trace_propagation_targets_matching(
190190
requests.get("http://example.com")
191191

192192
# CHECK if performance data (a transaction/span) is sent to Sentry
193-
if traces_sample_rate is None or incoming_parent_sampled == "0":
193+
if (
194+
traces_sample_rate is None
195+
or traces_sample_rate == USE_DEFAULT_TRACES_SAMPLE_RATE
196+
or incoming_parent_sampled == "0"
197+
):
194198
assert len(events) == 0
195199
else:
196200
if incoming_parent_sampled == "1" or traces_sample_rate == 1:
@@ -264,7 +268,11 @@ def test_with_incoming_trace_and_trace_propagation_targets_not_matching(
264268
requests.get("http://example.com")
265269

266270
# CHECK if performance data (a transaction/span) is sent to Sentry
267-
if traces_sample_rate is None or incoming_parent_sampled == "0":
271+
if (
272+
traces_sample_rate is None
273+
or traces_sample_rate == USE_DEFAULT_TRACES_SAMPLE_RATE
274+
or incoming_parent_sampled == "0"
275+
):
268276
assert len(events) == 0
269277
else:
270278
if incoming_parent_sampled == "1" or traces_sample_rate == 1:

0 commit comments

Comments
 (0)