@@ -35,18 +35,14 @@ def client():
35
35
36
36
@pytest .mark .forked
37
37
@pytest_mark_django_db_decorator (transaction = True )
38
- @pytest .mark .parametrize ("enable_db_query_source" , [None , False ])
39
- def test_query_source_disabled (
40
- sentry_init , client , capture_events , enable_db_query_source
41
- ):
38
+ def test_query_source_disabled (sentry_init , client , capture_events ):
42
39
sentry_options = {
43
40
"integrations" : [DjangoIntegration ()],
44
41
"send_default_pii" : True ,
45
42
"traces_sample_rate" : 1.0 ,
43
+ "enable_db_query_source" : False ,
44
+ "db_query_source_threshold_ms" : 0 ,
46
45
}
47
- if enable_db_query_source is not None :
48
- sentry_options ["enable_db_query_source" ] = enable_db_query_source
49
- sentry_options ["db_query_source_threshold_ms" ] = 0
50
46
51
47
sentry_init (** sentry_options )
52
48
@@ -75,6 +71,50 @@ def test_query_source_disabled(
75
71
raise AssertionError ("No db span found" )
76
72
77
73
74
+ @pytest .mark .forked
75
+ @pytest_mark_django_db_decorator (transaction = True )
76
+ @pytest .mark .parametrize ("enable_db_query_source" , [None , True ])
77
+ def test_query_source_enabled (
78
+ sentry_init , client , capture_events , enable_db_query_source
79
+ ):
80
+ sentry_options = {
81
+ "integrations" : [DjangoIntegration ()],
82
+ "send_default_pii" : True ,
83
+ "traces_sample_rate" : 1.0 ,
84
+ "db_query_source_threshold_ms" : 0 ,
85
+ }
86
+
87
+ if enable_db_query_source is not None :
88
+ sentry_options ["enable_db_query_source" ] = enable_db_query_source
89
+
90
+ sentry_init (** sentry_options )
91
+
92
+ if "postgres" not in connections :
93
+ pytest .skip ("postgres tests disabled" )
94
+
95
+ # trigger Django to open a new connection by marking the existing one as None.
96
+ connections ["postgres" ].connection = None
97
+
98
+ events = capture_events ()
99
+
100
+ _ , status , _ = unpack_werkzeug_response (client .get (reverse ("postgres_select_orm" )))
101
+ assert status == "200 OK"
102
+
103
+ (event ,) = events
104
+ for span in event ["spans" ]:
105
+ if span .get ("op" ) == "db" and "auth_user" in span .get ("description" ):
106
+ data = span .get ("data" , {})
107
+
108
+ assert SPANDATA .CODE_LINENO in data
109
+ assert SPANDATA .CODE_NAMESPACE in data
110
+ assert SPANDATA .CODE_FILEPATH in data
111
+ assert SPANDATA .CODE_FUNCTION in data
112
+
113
+ break
114
+ else :
115
+ raise AssertionError ("No db span found" )
116
+
117
+
78
118
@pytest .mark .forked
79
119
@pytest_mark_django_db_decorator (transaction = True )
80
120
def test_query_source (sentry_init , client , capture_events ):
0 commit comments