@@ -362,3 +362,42 @@ def test_start_transaction_updates_scope_name_source(sentry_init):
362362 with start_transaction (name = "foobar" , source = "route" ):
363363 assert scope ._transaction == "foobar"
364364 assert scope ._transaction_info == {"source" : "route" }
365+
366+
367+ @pytest .mark .parametrize ("sampled" , (True , None ))
368+ def test_transaction_dropped_debug_not_started (sentry_init , sampled ):
369+ sentry_init (enable_tracing = True )
370+
371+ tx = Transaction (sampled = sampled )
372+
373+ with mock .patch ("sentry_sdk.tracing.logger" ) as mock_logger :
374+ with tx :
375+ pass
376+
377+ mock_logger .debug .assert_any_call (
378+ "Discarding transaction because it was not started with sentry_sdk.start_transaction"
379+ )
380+
381+ with pytest .raises (AssertionError ):
382+ # We should NOT see the "sampled = False" message here
383+ mock_logger .debug .assert_any_call (
384+ "Discarding transaction because sampled = False"
385+ )
386+
387+
388+ def test_transaction_dropeed_sampled_false (sentry_init ):
389+ sentry_init (enable_tracing = True )
390+
391+ tx = Transaction (sampled = False )
392+
393+ with mock .patch ("sentry_sdk.tracing.logger" ) as mock_logger :
394+ with sentry_sdk .start_transaction (tx ):
395+ pass
396+
397+ mock_logger .debug .assert_any_call ("Discarding transaction because sampled = False" )
398+
399+ with pytest .raises (AssertionError ):
400+ # We should not see the "not started" message here
401+ mock_logger .debug .assert_any_call (
402+ "Discarding transaction because it was not started with sentry_sdk.start_transaction"
403+ )
0 commit comments