23
23
requires_gevent = pytest .mark .skipif (gevent is None , reason = "gevent not enabled" )
24
24
25
25
26
- def experimental_options (mode = None , auto_start = None ):
27
- return {
28
- "_experiments" : {
29
- "continuous_profiling_auto_start" : auto_start ,
30
- "continuous_profiling_mode" : mode ,
26
+ def get_client_options (use_top_level_profiler_mode ):
27
+ def client_options (mode = None , auto_start = None , profile_session_sample_rate = 1.0 ):
28
+ if use_top_level_profiler_mode :
29
+ return {
30
+ "profiler_mode" : mode ,
31
+ "profile_session_sample_rate" : profile_session_sample_rate ,
32
+ "_experiments" : {
33
+ "continuous_profiling_auto_start" : auto_start ,
34
+ },
35
+ }
36
+ return {
37
+ "profile_session_sample_rate" : profile_session_sample_rate ,
38
+ "_experiments" : {
39
+ "continuous_profiling_auto_start" : auto_start ,
40
+ "continuous_profiling_mode" : mode ,
41
+ },
31
42
}
32
- }
43
+
44
+ return client_options
33
45
34
46
35
47
mock_sdk_info = {
@@ -42,7 +54,10 @@ def experimental_options(mode=None, auto_start=None):
42
54
@pytest .mark .parametrize ("mode" , [pytest .param ("foo" )])
43
55
@pytest .mark .parametrize (
44
56
"make_options" ,
45
- [pytest .param (experimental_options , id = "experiment" )],
57
+ [
58
+ pytest .param (get_client_options (True ), id = "non-experiment" ),
59
+ pytest .param (get_client_options (False ), id = "experiment" ),
60
+ ],
46
61
)
47
62
def test_continuous_profiler_invalid_mode (mode , make_options , teardown_profiling ):
48
63
with pytest .raises (ValueError ):
@@ -62,7 +77,10 @@ def test_continuous_profiler_invalid_mode(mode, make_options, teardown_profiling
62
77
)
63
78
@pytest .mark .parametrize (
64
79
"make_options" ,
65
- [pytest .param (experimental_options , id = "experiment" )],
80
+ [
81
+ pytest .param (get_client_options (True ), id = "non-experiment" ),
82
+ pytest .param (get_client_options (False ), id = "experiment" ),
83
+ ],
66
84
)
67
85
def test_continuous_profiler_valid_mode (mode , make_options , teardown_profiling ):
68
86
options = make_options (mode = mode )
@@ -82,7 +100,10 @@ def test_continuous_profiler_valid_mode(mode, make_options, teardown_profiling):
82
100
)
83
101
@pytest .mark .parametrize (
84
102
"make_options" ,
85
- [pytest .param (experimental_options , id = "experiment" )],
103
+ [
104
+ pytest .param (get_client_options (True ), id = "non-experiment" ),
105
+ pytest .param (get_client_options (False ), id = "experiment" ),
106
+ ],
86
107
)
87
108
def test_continuous_profiler_setup_twice (mode , make_options , teardown_profiling ):
88
109
options = make_options (mode = mode )
@@ -178,7 +199,10 @@ def assert_single_transaction_without_profile_chunks(envelopes):
178
199
)
179
200
@pytest .mark .parametrize (
180
201
"make_options" ,
181
- [pytest .param (experimental_options , id = "experiment" )],
202
+ [
203
+ pytest .param (get_client_options (True ), id = "non-experiment" ),
204
+ pytest .param (get_client_options (False ), id = "experiment" ),
205
+ ],
182
206
)
183
207
@mock .patch ("sentry_sdk.profiler.continuous_profiler.PROFILE_BUFFER_SECONDS" , 0.01 )
184
208
def test_continuous_profiler_auto_start_and_manual_stop (
@@ -191,7 +215,7 @@ def test_continuous_profiler_auto_start_and_manual_stop(
191
215
options = make_options (mode = mode , auto_start = True )
192
216
sentry_init (
193
217
traces_sample_rate = 1.0 ,
194
- _experiments = options . get ( "_experiments" , {}) ,
218
+ ** options ,
195
219
)
196
220
197
221
envelopes = capture_envelopes ()
@@ -235,10 +259,13 @@ def test_continuous_profiler_auto_start_and_manual_stop(
235
259
)
236
260
@pytest .mark .parametrize (
237
261
"make_options" ,
238
- [pytest .param (experimental_options , id = "experiment" )],
262
+ [
263
+ pytest .param (get_client_options (True ), id = "non-experiment" ),
264
+ pytest .param (get_client_options (False ), id = "experiment" ),
265
+ ],
239
266
)
240
267
@mock .patch ("sentry_sdk.profiler.continuous_profiler.PROFILE_BUFFER_SECONDS" , 0.01 )
241
- def test_continuous_profiler_manual_start_and_stop (
268
+ def test_continuous_profiler_manual_start_and_stop_sampled (
242
269
sentry_init ,
243
270
capture_envelopes ,
244
271
mode ,
@@ -248,7 +275,7 @@ def test_continuous_profiler_manual_start_and_stop(
248
275
options = make_options (mode = mode )
249
276
sentry_init (
250
277
traces_sample_rate = 1.0 ,
251
- _experiments = options . get ( "_experiments" , {}) ,
278
+ ** options ,
252
279
)
253
280
254
281
envelopes = capture_envelopes ()
@@ -275,3 +302,43 @@ def test_continuous_profiler_manual_start_and_stop(
275
302
time .sleep (0.05 )
276
303
277
304
assert_single_transaction_without_profile_chunks (envelopes )
305
+
306
+
307
+ @pytest .mark .parametrize (
308
+ "mode" ,
309
+ [
310
+ pytest .param ("thread" ),
311
+ pytest .param ("gevent" , marks = requires_gevent ),
312
+ ],
313
+ )
314
+ @pytest .mark .parametrize (
315
+ "make_options" ,
316
+ [
317
+ pytest .param (get_client_options (True ), id = "non-experiment" ),
318
+ pytest .param (get_client_options (False ), id = "experiment" ),
319
+ ],
320
+ )
321
+ def test_continuous_profiler_manual_start_and_stop_unsampled (
322
+ sentry_init ,
323
+ capture_envelopes ,
324
+ mode ,
325
+ make_options ,
326
+ teardown_profiling ,
327
+ ):
328
+ options = make_options (mode = mode , profile_session_sample_rate = 0.0 )
329
+ sentry_init (
330
+ traces_sample_rate = 1.0 ,
331
+ ** options ,
332
+ )
333
+
334
+ envelopes = capture_envelopes ()
335
+
336
+ start_profiler ()
337
+
338
+ with sentry_sdk .start_transaction (name = "profiling" ):
339
+ with sentry_sdk .start_span (op = "op" ):
340
+ time .sleep (0.05 )
341
+
342
+ assert_single_transaction_without_profile_chunks (envelopes )
343
+
344
+ stop_profiler ()
0 commit comments