@@ -58,7 +58,7 @@ def mock_putheader_fn(self, header, value):
58
58
"traces_sample_rate=1" ,
59
59
],
60
60
)
61
- def test_no_incoming_trace_and_trace_targets_matching (
61
+ def test_no_incoming_trace_and_trace_propagation_targets_matching (
62
62
sentry_init , capture_events , _mock_putheader , traces_sample_rate
63
63
):
64
64
init_kwargs = {}
@@ -107,17 +107,23 @@ def test_no_incoming_trace_and_trace_targets_matching(
107
107
"traces_sample_rate=1" ,
108
108
],
109
109
)
110
- def test_with_incoming_trace_and_trace_targets_matching (
110
+ def test_no_incoming_trace_and_trace_propagation_targets_not_matching (
111
111
sentry_init , capture_events , _mock_putheader , traces_sample_rate
112
112
):
113
- init_kwargs = {}
113
+ init_kwargs = {
114
+ "trace_propagation_targets" : [
115
+ "http://someothersite.com" ,
116
+ ],
117
+ }
114
118
if traces_sample_rate != USE_DEFAULT_TRACES_SAMPLE_RATE :
115
119
init_kwargs ["traces_sample_rate" ] = traces_sample_rate
116
120
sentry_init (** init_kwargs )
117
121
118
122
events = capture_events ()
119
123
120
- with sentry_sdk .continue_trace (INCOMING_HEADERS ):
124
+ NO_INCOMING_HEADERS = {} # noqa: N806
125
+
126
+ with sentry_sdk .continue_trace (NO_INCOMING_HEADERS ):
121
127
with sentry_sdk .start_span (op = "test" , name = "test" ):
122
128
requests .get ("http://example.com" )
123
129
@@ -130,18 +136,11 @@ def test_with_incoming_trace_and_trace_targets_matching(
130
136
outgoing_request_headers = {key : value for key , value in _mock_putheader }
131
137
132
138
# CHECK if trace information is added to the outgoing request
133
- assert "sentry-trace" in outgoing_request_headers
134
- assert "baggage" in outgoing_request_headers
139
+ assert "sentry-trace" not in outgoing_request_headers
140
+ assert "baggage" not in outgoing_request_headers
135
141
136
142
# CHECK if incoming trace is continued
137
- if traces_sample_rate in (0 , 1 , USE_DEFAULT_TRACES_SAMPLE_RATE ):
138
- # continue the incoming trace
139
- assert INCOMING_TRACE_ID in outgoing_request_headers ["sentry-trace" ]
140
- assert INCOMING_TRACE_ID in outgoing_request_headers ["baggage" ]
141
- elif traces_sample_rate is None :
142
- # do NOT continue the incoming trace
143
- assert INCOMING_TRACE_ID not in outgoing_request_headers ["sentry-trace" ]
144
- assert INCOMING_TRACE_ID not in outgoing_request_headers ["baggage" ]
143
+ # (no assert necessary, because the trace information is not added to the outgoing request (see previous asserts))
145
144
146
145
147
146
@pytest .mark .parametrize (
@@ -159,23 +158,30 @@ def test_with_incoming_trace_and_trace_targets_matching(
159
158
"traces_sample_rate=1" ,
160
159
],
161
160
)
162
- def test_no_incoming_trace_and_trace_targets_not_matching (
163
- sentry_init , capture_events , _mock_putheader , traces_sample_rate
161
+ @pytest .mark .parametrize (
162
+ "incoming_parent_sampled" ,
163
+ ["deferred" , "1" , "0" ],
164
+ ids = [
165
+ "incoming_parent_sampled=DEFERRED" ,
166
+ "incoming_parent_sampled=1" ,
167
+ "incoming_parent_sampled=0" ,
168
+ ],
169
+ )
170
+ def test_with_incoming_trace_and_trace_propagation_targets_matching (
171
+ sentry_init ,
172
+ capture_events ,
173
+ _mock_putheader ,
174
+ incoming_parent_sampled ,
175
+ traces_sample_rate ,
164
176
):
165
- init_kwargs = {
166
- "trace_propagation_targets" : [
167
- "http://someothersite.com" ,
168
- ],
169
- }
177
+ init_kwargs = {}
170
178
if traces_sample_rate != USE_DEFAULT_TRACES_SAMPLE_RATE :
171
179
init_kwargs ["traces_sample_rate" ] = traces_sample_rate
172
180
sentry_init (** init_kwargs )
173
181
174
182
events = capture_events ()
175
183
176
- NO_INCOMING_HEADERS = {} # noqa: N806
177
-
178
- with sentry_sdk .continue_trace (NO_INCOMING_HEADERS ):
184
+ with sentry_sdk .continue_trace (INCOMING_HEADERS ):
179
185
with sentry_sdk .start_span (op = "test" , name = "test" ):
180
186
requests .get ("http://example.com" )
181
187
@@ -188,11 +194,18 @@ def test_no_incoming_trace_and_trace_targets_not_matching(
188
194
outgoing_request_headers = {key : value for key , value in _mock_putheader }
189
195
190
196
# CHECK if trace information is added to the outgoing request
191
- assert "sentry-trace" not in outgoing_request_headers
192
- assert "baggage" not in outgoing_request_headers
197
+ assert "sentry-trace" in outgoing_request_headers
198
+ assert "baggage" in outgoing_request_headers
193
199
194
200
# CHECK if incoming trace is continued
195
- # (no assert necessary, because the trace information is not added to the outgoing request (see previous asserts))
201
+ if traces_sample_rate in (0 , 1 , USE_DEFAULT_TRACES_SAMPLE_RATE ):
202
+ # continue the incoming trace
203
+ assert INCOMING_TRACE_ID in outgoing_request_headers ["sentry-trace" ]
204
+ assert INCOMING_TRACE_ID in outgoing_request_headers ["baggage" ]
205
+ elif traces_sample_rate is None :
206
+ # do NOT continue the incoming trace
207
+ assert INCOMING_TRACE_ID not in outgoing_request_headers ["sentry-trace" ]
208
+ assert INCOMING_TRACE_ID not in outgoing_request_headers ["baggage" ]
196
209
197
210
198
211
@pytest .mark .parametrize (
@@ -210,8 +223,21 @@ def test_no_incoming_trace_and_trace_targets_not_matching(
210
223
"traces_sample_rate=1" ,
211
224
],
212
225
)
213
- def test_with_incoming_trace_and_trace_targets_not_matching (
214
- sentry_init , capture_events , _mock_putheader , traces_sample_rate
226
+ @pytest .mark .parametrize (
227
+ "incoming_parent_sampled" ,
228
+ ["deferred" , "1" , "0" ],
229
+ ids = [
230
+ "incoming_parent_sampled=DEFERRED" ,
231
+ "incoming_parent_sampled=1" ,
232
+ "incoming_parent_sampled=0" ,
233
+ ],
234
+ )
235
+ def test_with_incoming_trace_and_trace_propagation_targets_not_matching (
236
+ sentry_init ,
237
+ capture_events ,
238
+ _mock_putheader ,
239
+ incoming_parent_sampled ,
240
+ traces_sample_rate ,
215
241
):
216
242
init_kwargs = {
217
243
"trace_propagation_targets" : [
0 commit comments