@@ -130,7 +130,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
130130 )
131131
132132
133- def test_outgoing_trace_headers (sentry_init , monkeypatch ):
133+ def test_outgoing_trace_headers (sentry_init , monkeypatch , capture_envelopes ):
134134 # HTTPSConnection.send is passed a string containing (among other things)
135135 # the headers on the request. Mock it so we can check the headers, and also
136136 # so it doesn't try to actually talk to the internet.
@@ -139,6 +139,8 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
139139
140140 sentry_init (traces_sample_rate = 1.0 )
141141
142+ envelopes = capture_envelopes ()
143+
142144 headers = {}
143145 headers ["baggage" ] = (
144146 "other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, "
@@ -163,25 +165,28 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
163165 key , val = line .split (": " )
164166 request_headers [key ] = val
165167
166- request_span = transaction ._span_recorder .spans [- 1 ]
167- expected_sentry_trace = "{trace_id}-{parent_span_id}-{sampled}" .format (
168- trace_id = transaction .trace_id ,
169- parent_span_id = request_span .span_id ,
170- sampled = 1 ,
171- )
172- assert request_headers ["sentry-trace" ] == expected_sentry_trace
168+ (envelope ,) = envelopes
169+ transaction = envelope .get_transaction_event ()
170+ request_span = transaction ["spans" ][- 1 ]
173171
174- expected_outgoing_baggage = (
175- "sentry-trace_id=771a43a4192642f0b136d5159a501700,"
176- "sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
177- "sentry-sample_rate=0.01337,"
178- "sentry-user_id=Am%C3%A9lie"
179- )
172+ expected_sentry_trace = "{trace_id}-{parent_span_id}-{sampled}" .format (
173+ trace_id = transaction ["contexts" ]["trace" ]["trace_id" ],
174+ parent_span_id = request_span ["span_id" ],
175+ sampled = 1 ,
176+ )
177+ assert request_headers ["sentry-trace" ] == expected_sentry_trace
178+
179+ expected_outgoing_baggage = (
180+ "sentry-trace_id=771a43a4192642f0b136d5159a501700,"
181+ "sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
182+ "sentry-sample_rate=0.01337,"
183+ "sentry-user_id=Am%C3%A9lie"
184+ )
180185
181- assert request_headers ["baggage" ] == expected_outgoing_baggage
186+ assert request_headers ["baggage" ] == expected_outgoing_baggage
182187
183188
184- def test_outgoing_trace_headers_head_sdk (sentry_init , monkeypatch ):
189+ def test_outgoing_trace_headers_head_sdk (sentry_init , monkeypatch , capture_envelopes ):
185190 # HTTPSConnection.send is passed a string containing (among other things)
186191 # the headers on the request. Mock it so we can check the headers, and also
187192 # so it doesn't try to actually talk to the internet.
@@ -192,6 +197,9 @@ def test_outgoing_trace_headers_head_sdk(sentry_init, monkeypatch):
192197 monkeypatch .setattr (random , "random" , lambda : 0.1 )
193198
194199 sentry_init (traces_sample_rate = 0.5 , release = "foo" )
200+
201+ envelopes = capture_envelopes ()
202+
195203 transaction = Transaction .continue_from_headers ({})
196204
197205 with start_transaction (transaction = transaction , name = "Head SDK tx" ) as transaction :
@@ -204,23 +212,26 @@ def test_outgoing_trace_headers_head_sdk(sentry_init, monkeypatch):
204212 key , val = line .split (": " )
205213 request_headers [key ] = val
206214
207- request_span = transaction ._span_recorder .spans [- 1 ]
208- expected_sentry_trace = "{trace_id}-{parent_span_id}-{sampled}" .format (
209- trace_id = transaction .trace_id ,
210- parent_span_id = request_span .span_id ,
211- sampled = 1 ,
212- )
213- assert request_headers ["sentry-trace" ] == expected_sentry_trace
215+ (envelope ,) = envelopes
216+ transaction = envelope .get_transaction_event ()
217+ request_span = transaction ["spans" ][- 1 ]
218+
219+ expected_sentry_trace = "{trace_id}-{parent_span_id}-{sampled}" .format (
220+ trace_id = transaction ["contexts" ]["trace" ]["trace_id" ],
221+ parent_span_id = request_span ["span_id" ],
222+ sampled = 1 ,
223+ )
224+ assert request_headers ["sentry-trace" ] == expected_sentry_trace
214225
215- expected_outgoing_baggage = (
216- "sentry-trace_id=%s,"
217- "sentry-environment=production,"
218- "sentry-release=foo,"
219- "sentry-sample_rate=0.5,"
220- "sentry-sampled=%s"
221- ) % (transaction .trace_id , "true" if transaction .sampled else "false" )
226+ expected_outgoing_baggage = (
227+ "sentry-trace_id=%s,"
228+ "sentry-environment=production,"
229+ "sentry-release=foo,"
230+ "sentry-sample_rate=0.5,"
231+ "sentry-sampled=%s"
232+ ) % (transaction .trace_id , "true" if transaction .sampled else "false" )
222233
223- assert request_headers ["baggage" ] == expected_outgoing_baggage
234+ assert request_headers ["baggage" ] == expected_outgoing_baggage
224235
225236
226237@pytest .mark .parametrize (
0 commit comments