7
7
8
8
INCOMING_TRACE_ID = "771a43a4192642f0b136d5159a501700"
9
9
INCOMING_HEADERS = {
10
- "sentry-trace" : f"{ INCOMING_TRACE_ID } -1234567890abcdef-1 " ,
10
+ "sentry-trace" : f"{ INCOMING_TRACE_ID } -1234567890abcdef" ,
11
11
"baggage" : (
12
12
f"sentry-trace_id={ INCOMING_TRACE_ID } , "
13
13
"sentry-public_key=frontendpublickey,"
14
14
"sentry-sample_rate=0.01337,"
15
- "sentry-sampled=true,"
16
15
"sentry-release=myfrontend,"
17
16
"sentry-environment=bird,"
18
17
"sentry-transaction=bar"
@@ -49,7 +48,7 @@ def mock_putheader_fn(self, header, value):
49
48
USE_DEFAULT_TRACES_SAMPLE_RATE ,
50
49
None ,
51
50
0 ,
52
- 1.0 ,
51
+ 1 ,
53
52
],
54
53
ids = [
55
54
"traces_sample_rate=DEFAULT" ,
@@ -98,7 +97,7 @@ def test_no_incoming_trace_and_trace_propagation_targets_matching(
98
97
USE_DEFAULT_TRACES_SAMPLE_RATE ,
99
98
None ,
100
99
0 ,
101
- 1.0 ,
100
+ 1 ,
102
101
],
103
102
ids = [
104
103
"traces_sample_rate=DEFAULT" ,
@@ -149,7 +148,7 @@ def test_no_incoming_trace_and_trace_propagation_targets_not_matching(
149
148
USE_DEFAULT_TRACES_SAMPLE_RATE ,
150
149
None ,
151
150
0 ,
152
- 1.0 ,
151
+ 1 ,
153
152
],
154
153
ids = [
155
154
"traces_sample_rate=DEFAULT" ,
@@ -181,15 +180,29 @@ def test_with_incoming_trace_and_trace_propagation_targets_matching(
181
180
182
181
events = capture_events ()
183
182
184
- with sentry_sdk .continue_trace (INCOMING_HEADERS ):
183
+ incoming_headers = INCOMING_HEADERS .copy ()
184
+ if incoming_parent_sampled != "deferred" :
185
+ incoming_headers ["sentry-trace" ] += f"-{ incoming_parent_sampled } "
186
+ incoming_headers [
187
+ "baggage"
188
+ ] += f',sentry-sampled={ "true" if incoming_parent_sampled == "1" else "false" } ' # noqa: E231
189
+
190
+ print ("~~~~~~~~~~~~~~~~~~~~" )
191
+ print (incoming_headers )
192
+ print ("~~~~~~~~~~~~~~~~~~~~" )
193
+ with sentry_sdk .continue_trace (incoming_headers ):
185
194
with sentry_sdk .start_span (op = "test" , name = "test" ):
186
195
requests .get ("http://example.com" )
187
196
188
197
# CHECK if performance data (a transaction/span) is sent to Sentry
189
198
if traces_sample_rate == 1 :
190
199
assert len (events ) == 1
191
- else :
200
+ elif traces_sample_rate == 0 :
201
+ assert len (events ) == 1
202
+ elif traces_sample_rate in (None , USE_DEFAULT_TRACES_SAMPLE_RATE ):
192
203
assert len (events ) == 0
204
+ else :
205
+ raise AssertionError (f"Invalid traces_sample_rate: { traces_sample_rate } " )
193
206
194
207
outgoing_request_headers = {key : value for key , value in _mock_putheader }
195
208
@@ -214,7 +227,7 @@ def test_with_incoming_trace_and_trace_propagation_targets_matching(
214
227
USE_DEFAULT_TRACES_SAMPLE_RATE ,
215
228
None ,
216
229
0 ,
217
- 1.0 ,
230
+ 1 ,
218
231
],
219
232
ids = [
220
233
"traces_sample_rate=DEFAULT" ,
@@ -250,13 +263,22 @@ def test_with_incoming_trace_and_trace_propagation_targets_not_matching(
250
263
251
264
events = capture_events ()
252
265
253
- with sentry_sdk .continue_trace (INCOMING_HEADERS ):
266
+ incoming_headers = INCOMING_HEADERS .copy ()
267
+ if incoming_parent_sampled != "deferred" :
268
+ incoming_headers ["sentry-trace" ] += f"-{ incoming_parent_sampled } "
269
+ incoming_headers [
270
+ "baggage"
271
+ ] += f',sentry-sampled={ "true" if incoming_parent_sampled == "1" else "false" } ' # noqa: E231
272
+
273
+ with sentry_sdk .continue_trace (incoming_headers ):
254
274
with sentry_sdk .start_span (op = "test" , name = "test" ):
255
275
requests .get ("http://example.com" )
256
276
257
277
# CHECK if performance data (a transaction/span) is sent to Sentry
258
278
if traces_sample_rate == 1 :
259
279
assert len (events ) == 1
280
+ elif traces_sample_rate == 0 :
281
+ assert len (events ) == 1
260
282
else :
261
283
assert len (events ) == 0
262
284
0 commit comments