@@ -104,14 +104,16 @@ async def test_async_views(sentry_init, capture_events, application):
104104@pytest .mark .skipif (
105105 django .VERSION < (3 , 1 ), reason = "async views have been introduced in Django 3.1"
106106)
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+ ):
108110 with mock .patch (
109111 "sentry_sdk.profiler.transaction_profiler.PROFILE_MINIMUM_SAMPLES" , 0
110112 ):
111113 sentry_init (
112114 integrations = [DjangoIntegration ()],
113115 traces_sample_rate = 1.0 ,
114- _experiments = { " profiles_sample_rate" : 1.0 } ,
116+ profiles_sample_rate = 1.0 ,
115117 )
116118
117119 envelopes = capture_envelopes ()
@@ -121,17 +123,26 @@ async def test_active_thread_id(sentry_init, capture_envelopes, endpoint, applic
121123 await comm .wait ()
122124
123125 assert response ["status" ] == 200 , response ["body" ]
124- assert len (envelopes ) == 1
125126
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" ]
128138
129- data = json .loads (response ["body" ])
139+ transactions = [item for item in envelopes [0 ].items if item .type == "transaction" ]
140+ assert len (transactions ) == 1
130141
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 " ]
135146
136147
137148@pytest .mark .asyncio
0 commit comments