@@ -284,3 +284,61 @@ def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value(
284284 transaction = start_transaction (name = "dogpark" )
285285 logger .warning .assert_any_call (StringContaining ("Given sample rate is invalid" ))
286286 assert transaction .sampled is False
287+
288+
289+ @pytest .mark .parametrize (
290+ "traces_sample_rate,sampled_output,reports_output" ,
291+ [
292+ (None , False , []),
293+ (0.0 , False , [("sample_rate" , "transaction" )]),
294+ (1.0 , True , []),
295+ ],
296+ )
297+ def test_records_lost_event_only_if_traces_sample_rate_enabled (
298+ sentry_init , traces_sample_rate , sampled_output , reports_output , monkeypatch
299+ ):
300+ reports = []
301+
302+ def record_lost_event (reason , data_category = None , item = None ):
303+ reports .append ((reason , data_category ))
304+
305+ sentry_init (traces_sample_rate = traces_sample_rate )
306+
307+ monkeypatch .setattr (
308+ Hub .current .client .transport , "record_lost_event" , record_lost_event
309+ )
310+
311+ transaction = start_transaction (name = "dogpark" )
312+ assert transaction .sampled is sampled_output
313+ transaction .finish ()
314+
315+ assert reports == reports_output
316+
317+
318+ @pytest .mark .parametrize (
319+ "traces_sampler,sampled_output,reports_output" ,
320+ [
321+ (None , False , []),
322+ (lambda _x : 0.0 , False , [("sample_rate" , "transaction" )]),
323+ (lambda _x : 1.0 , True , []),
324+ ],
325+ )
326+ def test_records_lost_event_only_if_traces_sampler_enabled (
327+ sentry_init , traces_sampler , sampled_output , reports_output , monkeypatch
328+ ):
329+ reports = []
330+
331+ def record_lost_event (reason , data_category = None , item = None ):
332+ reports .append ((reason , data_category ))
333+
334+ sentry_init (traces_sampler = traces_sampler )
335+
336+ monkeypatch .setattr (
337+ Hub .current .client .transport , "record_lost_event" , record_lost_event
338+ )
339+
340+ transaction = start_transaction (name = "dogpark" )
341+ assert transaction .sampled is sampled_output
342+ transaction .finish ()
343+
344+ assert reports == reports_output
0 commit comments