Skip to content

Commit ceb1b47

Browse files
committed
Update some tests to new default value
1 parent d5baffe commit ceb1b47

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

tests/integrations/aiohttp/test_aiohttp.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,10 @@ async def hello(request):
448448
async def test_trace_from_headers_if_performance_disabled(
449449
sentry_init, aiohttp_client, capture_events
450450
):
451-
sentry_init(integrations=[AioHttpIntegration()])
451+
sentry_init(
452+
integrations=[AioHttpIntegration()],
453+
traces_sample_rate=None, # disable all performance monitoring
454+
)
452455

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

tests/integrations/asgi/test_asgi.py

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

275277
with pytest.raises(ZeroDivisionError):

tests/integrations/django/test_basic.py

+1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ 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
244245
)
245246

246247
events = capture_events()

tests/integrations/opentelemetry/test_sampler.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
import sentry_sdk
77

88

9+
USE_DEFAULT_TRACES_SAMPLE_RATE = -1
10+
911
tracer = trace.get_tracer(__name__)
1012

1113

1214
@pytest.mark.parametrize(
1315
"traces_sample_rate, expected_num_of_envelopes",
1416
[
15-
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used)
16-
(-1, 0),
17+
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used)
18+
(USE_DEFAULT_TRACES_SAMPLE_RATE, 0),
1719
# traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all.
1820
(None, 0),
1921
# 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.
@@ -29,7 +31,7 @@ def test_sampling_traces_sample_rate_0_or_100(
2931
expected_num_of_envelopes,
3032
):
3133
kwargs = {}
32-
if traces_sample_rate != -1:
34+
if traces_sample_rate != USE_DEFAULT_TRACES_SAMPLE_RATE:
3335
kwargs["traces_sample_rate"] = traces_sample_rate
3436

3537
sentry_init(**kwargs)
@@ -176,8 +178,8 @@ def keep_only_a(sampling_context):
176178
@pytest.mark.parametrize(
177179
"traces_sample_rate, expected_num_of_envelopes",
178180
[
179-
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used)
180-
(-1, 0),
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),
181183
# traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all.
182184
(None, 0),
183185
# 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.
@@ -193,7 +195,7 @@ def test_sampling_parent_sampled(
193195
capture_envelopes,
194196
):
195197
kwargs = {}
196-
if traces_sample_rate != -1:
198+
if traces_sample_rate != USE_DEFAULT_TRACES_SAMPLE_RATE:
197199
kwargs["traces_sample_rate"] = traces_sample_rate
198200

199201
sentry_init(**kwargs)
@@ -227,9 +229,11 @@ def test_sampling_parent_sampled(
227229
@pytest.mark.parametrize(
228230
"traces_sample_rate, upstream_sampled, expected_num_of_envelopes",
229231
[
230-
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used)
231-
(-1, 0, 0),
232+
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used)
233+
(USE_DEFAULT_TRACES_SAMPLE_RATE, 0, 0),
234+
(USE_DEFAULT_TRACES_SAMPLE_RATE, 1, 1),
232235
# traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all.
236+
(None, 0, 0),
233237
(None, 1, 0),
234238
# 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.
235239
(0, 0, 0),
@@ -247,7 +251,7 @@ def test_sampling_parent_dropped(
247251
capture_envelopes,
248252
):
249253
kwargs = {}
250-
if traces_sample_rate != -1:
254+
if traces_sample_rate != USE_DEFAULT_TRACES_SAMPLE_RATE:
251255
kwargs["traces_sample_rate"] = traces_sample_rate
252256

253257
sentry_init(**kwargs)
@@ -281,8 +285,8 @@ def test_sampling_parent_dropped(
281285
@pytest.mark.parametrize(
282286
"traces_sample_rate, expected_num_of_envelopes",
283287
[
284-
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=None will be used)
285-
(-1, 0),
288+
# special case for testing, do not pass any traces_sample_rate to init() (the default traces_sample_rate=0 will be used)
289+
(USE_DEFAULT_TRACES_SAMPLE_RATE, 0),
286290
# traces_sample_rate=None means do not create new traces, and also do not continue incoming traces. So, no envelopes at all.
287291
(None, 0),
288292
# 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.
@@ -298,7 +302,7 @@ def test_sampling_parent_deferred(
298302
capture_envelopes,
299303
):
300304
kwargs = {}
301-
if traces_sample_rate != -1:
305+
if traces_sample_rate != USE_DEFAULT_TRACES_SAMPLE_RATE:
302306
kwargs["traces_sample_rate"] = traces_sample_rate
303307

304308
sentry_init(**kwargs)

tests/integrations/wsgi/test_wsgi.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ 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()
241+
sentry_init(
242+
traces_sample_rate=None, # disable all performance monitoring
243+
)
242244
app = SentryWsgiMiddleware(dogpark)
243245
client = Client(app)
244246
events = capture_events()
@@ -301,7 +303,9 @@ def dogpark(environ, start_response):
301303
capture_message("Attempting to fetch the ball")
302304
raise ValueError("Fetch aborted. The ball was not returned.")
303305

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

0 commit comments

Comments
 (0)