1- import random
21from http .client import HTTPConnection , HTTPSConnection
32from socket import SocketIO
43from urllib .error import HTTPError
@@ -207,7 +206,7 @@ def test_outgoing_trace_headers(
207206 "baggage" : (
208207 "other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, "
209208 "sentry-public_key=49d0f7386ad645858ae85020e393bef3, sentry-sample_rate=0.01337, "
210- "sentry-user_id=Am%C3%A9lie, other-vendor-value-2=foo;bar;"
209+ "sentry-user_id=Am%C3%A9lie, sentry-sample_rand=0.132521102938283, other-vendor-value-2=foo;bar;"
211210 ),
212211 }
213212
@@ -233,28 +232,27 @@ def test_outgoing_trace_headers(
233232 "sentry-trace_id=771a43a4192642f0b136d5159a501700,"
234233 "sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
235234 "sentry-sample_rate=1.0,"
236- "sentry-user_id=Am%C3%A9lie"
235+ "sentry-user_id=Am%C3%A9lie,"
236+ "sentry-sample_rand=0.132521102938283"
237237 )
238238
239239 assert request_headers ["baggage" ] == SortedBaggage (expected_outgoing_baggage )
240240
241241
242242def test_outgoing_trace_headers_head_sdk (
243- sentry_init , monkeypatch , capture_request_headers , capture_envelopes
243+ sentry_init , capture_request_headers , capture_envelopes
244244):
245- # make sure transaction is always sampled
246- monkeypatch .setattr (random , "random" , lambda : 0.1 )
247-
248245 sentry_init (traces_sample_rate = 0.5 , release = "foo" )
249246 envelopes = capture_envelopes ()
250247 request_headers = capture_request_headers ()
251248
252- with isolation_scope ():
253- with continue_trace ({}):
254- with start_span (name = "Head SDK tx" ) as root_span :
255- conn = HTTPConnection ("localhost" , PORT )
256- conn .request ("GET" , "/top-chasers" )
257- conn .getresponse ()
249+ with mock .patch ("sentry_sdk.tracing_utils.Random.uniform" , return_value = 0.25 ):
250+ with isolation_scope ():
251+ with continue_trace ({}):
252+ with start_span (name = "Head SDK tx" ) as root_span :
253+ conn = HTTPConnection ("localhost" , PORT )
254+ conn .request ("GET" , "/top-chasers" )
255+ conn .getresponse ()
258256
259257 (envelope ,) = envelopes
260258 transaction = envelope .get_transaction_event ()
@@ -269,6 +267,7 @@ def test_outgoing_trace_headers_head_sdk(
269267
270268 expected_outgoing_baggage = (
271269 f"sentry-trace_id={ root_span .trace_id } ," # noqa: E231
270+ "sentry-sample_rand=0.250000,"
272271 "sentry-environment=production,"
273272 "sentry-release=foo,"
274273 "sentry-sample_rate=0.5,"
0 commit comments