@@ -130,7 +130,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
130
130
)
131
131
132
132
133
- def test_outgoing_trace_headers (sentry_init , monkeypatch ):
133
+ def test_outgoing_trace_headers (sentry_init , monkeypatch , capture_envelopes ):
134
134
# HTTPSConnection.send is passed a string containing (among other things)
135
135
# the headers on the request. Mock it so we can check the headers, and also
136
136
# so it doesn't try to actually talk to the internet.
@@ -139,6 +139,8 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
139
139
140
140
sentry_init (traces_sample_rate = 1.0 )
141
141
142
+ envelopes = capture_envelopes ()
143
+
142
144
headers = {}
143
145
headers ["baggage" ] = (
144
146
"other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, "
@@ -163,25 +165,28 @@ def test_outgoing_trace_headers(sentry_init, monkeypatch):
163
165
key , val = line .split (": " )
164
166
request_headers [key ] = val
165
167
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 ]
173
171
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
+ )
180
185
181
- assert request_headers ["baggage" ] == expected_outgoing_baggage
186
+ assert request_headers ["baggage" ] == expected_outgoing_baggage
182
187
183
188
184
- def test_outgoing_trace_headers_head_sdk (sentry_init , monkeypatch ):
189
+ def test_outgoing_trace_headers_head_sdk (sentry_init , monkeypatch , capture_envelopes ):
185
190
# HTTPSConnection.send is passed a string containing (among other things)
186
191
# the headers on the request. Mock it so we can check the headers, and also
187
192
# 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):
192
197
monkeypatch .setattr (random , "random" , lambda : 0.1 )
193
198
194
199
sentry_init (traces_sample_rate = 0.5 , release = "foo" )
200
+
201
+ envelopes = capture_envelopes ()
202
+
195
203
transaction = Transaction .continue_from_headers ({})
196
204
197
205
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):
204
212
key , val = line .split (": " )
205
213
request_headers [key ] = val
206
214
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
214
225
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" )
222
233
223
- assert request_headers ["baggage" ] == expected_outgoing_baggage
234
+ assert request_headers ["baggage" ] == expected_outgoing_baggage
224
235
225
236
226
237
@pytest .mark .parametrize (
0 commit comments