@@ -624,3 +624,77 @@ 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 = [
639
+ DjangoIntegration (
640
+ middleware_spans = False ,
641
+ signals_spans = False ,
642
+ ),
643
+ ],
644
+ traces_sample_rate = 1.0 ,
645
+ )
646
+ events = capture_events ()
647
+
648
+ comm = HttpCommunicator (application , "GET" , "/simple_async_view" )
649
+ await comm .get_response ()
650
+ await comm .wait ()
651
+
652
+ comm = HttpCommunicator (application , "OPTIONS" , "/simple_async_view" )
653
+ await comm .get_response ()
654
+ await comm .wait ()
655
+
656
+ comm = HttpCommunicator (application , "HEAD" , "/simple_async_view" )
657
+ await comm .get_response ()
658
+ await comm .wait ()
659
+
660
+ (event ,) = events
661
+
662
+ assert len (events ) == 1
663
+ assert event ["request" ]["method" ] == "GET"
664
+
665
+
666
+ @pytest .mark .parametrize ("application" , APPS )
667
+ @pytest .mark .asyncio
668
+ async def test_transaction_http_method_custom (sentry_init , capture_events , application ):
669
+ sentry_init (
670
+ integrations = [
671
+ DjangoIntegration (
672
+ middleware_spans = False ,
673
+ signals_spans = False ,
674
+ http_methods_to_capture = (
675
+ "OPTIONS" ,
676
+ "head" ,
677
+ ), # capitalization does not matter
678
+ )
679
+ ],
680
+ traces_sample_rate = 1.0 ,
681
+ )
682
+ events = capture_events ()
683
+
684
+ comm = HttpCommunicator (application , "GET" , "/simple_async_view" )
685
+ await comm .get_response ()
686
+ await comm .wait ()
687
+
688
+ comm = HttpCommunicator (application , "OPTIONS" , "/simple_async_view" )
689
+ await comm .get_response ()
690
+ await comm .wait ()
691
+
692
+ comm = HttpCommunicator (application , "HEAD" , "/simple_async_view" )
693
+ await comm .get_response ()
694
+ await comm .wait ()
695
+
696
+ assert len (events ) == 2
697
+
698
+ (event1 , event2 ) = events
699
+ assert event1 ["request" ]["method" ] == "OPTIONS"
700
+ assert event2 ["request" ]["method" ] == "HEAD"
0 commit comments