@@ -624,3 +624,70 @@ async def test_async_view(sentry_init, capture_events, application):
624
624
(event ,) = events
625
625
assert event ["type" ] == "transaction"
626
626
assert event ["transaction" ] == "/simple_async_view"
627
+
628
+
629
+ @pytest .mark .parametrize ("application" , APPS )
630
+ @pytest .mark .asyncio
631
+ async def test_transaction_http_method_default (
632
+ sentry_init , capture_events , application
633
+ ):
634
+ """
635
+ By default OPTIONS and HEAD requests do not create a transaction.
636
+ """
637
+ sentry_init (
638
+ integrations = [DjangoIntegration ()],
639
+ traces_sample_rate = 1.0 ,
640
+ )
641
+ events = capture_events ()
642
+
643
+ comm = HttpCommunicator (application , "GET" , "/simple_async_view" )
644
+ await comm .get_response ()
645
+ await comm .wait ()
646
+
647
+ comm = HttpCommunicator (application , "OPTIONS" , "/simple_async_view" )
648
+ await comm .get_response ()
649
+ await comm .wait ()
650
+
651
+ comm = HttpCommunicator (application , "HEAD" , "/simple_async_view" )
652
+ await comm .get_response ()
653
+ await comm .wait ()
654
+
655
+ (event ,) = events
656
+
657
+ assert len (events ) == 1
658
+ assert event ["request" ]["method" ] == "GET"
659
+
660
+
661
+ @pytest .mark .parametrize ("application" , APPS )
662
+ @pytest .mark .asyncio
663
+ async def test_transaction_http_method_custom (sentry_init , capture_events , application ):
664
+ sentry_init (
665
+ integrations = [
666
+ DjangoIntegration (
667
+ http_methods_to_capture = (
668
+ "OPTIONS" ,
669
+ "head" ,
670
+ ), # capitalization does not matter
671
+ )
672
+ ],
673
+ traces_sample_rate = 1.0 ,
674
+ )
675
+ events = capture_events ()
676
+
677
+ comm = HttpCommunicator (application , "GET" , "/simple_async_view" )
678
+ await comm .get_response ()
679
+ await comm .wait ()
680
+
681
+ comm = HttpCommunicator (application , "OPTIONS" , "/simple_async_view" )
682
+ await comm .get_response ()
683
+ await comm .wait ()
684
+
685
+ comm = HttpCommunicator (application , "HEAD" , "/simple_async_view" )
686
+ await comm .get_response ()
687
+ await comm .wait ()
688
+
689
+ assert len (events ) == 2
690
+
691
+ (event1 , event2 ) = events
692
+ assert event1 ["request" ]["method" ] == "OPTIONS"
693
+ assert event2 ["request" ]["method" ] == "HEAD"
0 commit comments