@@ -104,14 +104,16 @@ async def test_async_views(sentry_init, capture_events, application):
104
104
@pytest .mark .skipif (
105
105
django .VERSION < (3 , 1 ), reason = "async views have been introduced in Django 3.1"
106
106
)
107
- async def test_active_thread_id (sentry_init , capture_envelopes , endpoint , application ):
107
+ async def test_active_thread_id (
108
+ sentry_init , capture_envelopes , teardown_profiling , endpoint , application
109
+ ):
108
110
with mock .patch (
109
111
"sentry_sdk.profiler.transaction_profiler.PROFILE_MINIMUM_SAMPLES" , 0
110
112
):
111
113
sentry_init (
112
114
integrations = [DjangoIntegration ()],
113
115
traces_sample_rate = 1.0 ,
114
- _experiments = { " profiles_sample_rate" : 1.0 } ,
116
+ profiles_sample_rate = 1.0 ,
115
117
)
116
118
117
119
envelopes = capture_envelopes ()
@@ -121,17 +123,26 @@ async def test_active_thread_id(sentry_init, capture_envelopes, endpoint, applic
121
123
await comm .wait ()
122
124
123
125
assert response ["status" ] == 200 , response ["body" ]
124
- assert len (envelopes ) == 1
125
126
126
- profiles = [item for item in envelopes [0 ].items if item .type == "profile" ]
127
- assert len (profiles ) == 1
127
+ assert len (envelopes ) == 1
128
+
129
+ profiles = [item for item in envelopes [0 ].items if item .type == "profile" ]
130
+ assert len (profiles ) == 1
131
+
132
+ data = json .loads (response ["body" ])
133
+
134
+ for item in profiles :
135
+ transactions = item .payload .json ["transactions" ]
136
+ assert len (transactions ) == 1
137
+ assert str (data ["active" ]) == transactions [0 ]["active_thread_id" ]
128
138
129
- data = json .loads (response ["body" ])
139
+ transactions = [item for item in envelopes [0 ].items if item .type == "transaction" ]
140
+ assert len (transactions ) == 1
130
141
131
- for profile in profiles :
132
- transactions = profile .payload .json [ "transactions" ]
133
- assert len ( transactions ) == 1
134
- assert str (data ["active" ]) == transactions [ 0 ]["active_thread_id " ]
142
+ for item in transactions :
143
+ transaction = item .payload .json
144
+ trace_context = transaction [ "contexts" ][ "trace" ]
145
+ assert str (data ["active" ]) == trace_context [ "data" ]["thread.id " ]
135
146
136
147
137
148
@pytest .mark .asyncio
0 commit comments