@@ -51,9 +51,11 @@ def test_basic(sentry_init, capture_events, sample_rate):
5151 assert not events
5252
5353
54- @pytest .mark .parametrize ("sampled " , [True , False , None ])
54+ @pytest .mark .parametrize ("parent_sampled " , [True , False , None ])
5555@pytest .mark .parametrize ("sample_rate" , [0.0 , 1.0 ])
56- def test_continue_from_headers (sentry_init , capture_envelopes , sampled , sample_rate ):
56+ def test_continue_from_headers (
57+ sentry_init , capture_envelopes , parent_sampled , sample_rate
58+ ):
5759 """
5860 Ensure data is actually passed along via headers, and that they are read
5961 correctly.
@@ -64,7 +66,7 @@ def test_continue_from_headers(sentry_init, capture_envelopes, sampled, sample_r
6466 # make a parent transaction (normally this would be in a different service)
6567 with start_transaction (name = "hi" , sampled = True if sample_rate == 0 else None ):
6668 with start_span () as old_span :
67- old_span .sampled = sampled
69+ old_span .sampled = parent_sampled
6870 headers = dict (
6971 sentry_sdk .get_current_scope ().iter_trace_propagation_headers (old_span )
7072 )
@@ -79,7 +81,7 @@ def test_continue_from_headers(sentry_init, capture_envelopes, sampled, sample_r
7981 # child transaction, to prove that we can read 'sentry-trace' header data correctly
8082 child_transaction = Transaction .continue_from_headers (headers , name = "WRONG" )
8183 assert child_transaction is not None
82- assert child_transaction .parent_sampled == sampled
84+ assert child_transaction .parent_sampled == parent_sampled
8385 assert child_transaction .trace_id == old_span .trace_id
8486 assert child_transaction .same_process_as_parent is False
8587 assert child_transaction .parent_span_id == old_span .span_id
@@ -104,8 +106,8 @@ def test_continue_from_headers(sentry_init, capture_envelopes, sampled, sample_r
104106 sentry_sdk .get_current_scope ().transaction = "ho"
105107 capture_message ("hello" )
106108
107- # in this case the child transaction won't be captured
108- if sampled is False or ( sample_rate == 0 and sampled is None ):
109+ if parent_sampled is False or ( sample_rate == 0 and parent_sampled is None ):
110+ # in this case the child transaction won't be captured
109111 trace1 , message = envelopes
110112 message_payload = message .get_event ()
111113 trace1_payload = trace1 .get_transaction_event ()
@@ -127,12 +129,17 @@ def test_continue_from_headers(sentry_init, capture_envelopes, sampled, sample_r
127129 == message_payload ["contexts" ]["trace" ]["trace_id" ]
128130 )
129131
132+ if parent_sampled is not None :
133+ expected_sample_rate = str (float (parent_sampled ))
134+ else :
135+ expected_sample_rate = str (sample_rate )
136+
130137 assert trace2 .headers ["trace" ] == baggage .dynamic_sampling_context ()
131138 assert trace2 .headers ["trace" ] == {
132139 "public_key" : "49d0f7386ad645858ae85020e393bef3" ,
133140 "trace_id" : "771a43a4192642f0b136d5159a501700" ,
134141 "user_id" : "Amelie" ,
135- "sample_rate" : str ( sample_rate ) ,
142+ "sample_rate" : expected_sample_rate ,
136143 }
137144
138145 assert message_payload ["message" ] == "hello"
0 commit comments