@@ -25,6 +25,22 @@ def test_continue_trace_with_sample_rand():
2525 assert transaction .get_baggage ().sentry_items ["sample_rand" ] == "0.1"
2626
2727
28+ def test_continue_trace_with_sample_rand_span_streaming (sentry_init ):
29+ """
30+ Test that an incoming sample_rand is propagated onto the segment's baggage.
31+ """
32+ sentry_init (traces_sample_rate = 1.0 , _experiments = {"trace_lifecycle" : "stream" })
33+
34+ headers = {
35+ "sentry-trace" : "00000000000000000000000000000000-0000000000000000-1" ,
36+ "baggage" : "sentry-sample_rand=0.100000,sentry-sample_rate=0.5" ,
37+ }
38+
39+ sentry_sdk .traces .continue_trace (headers )
40+ with sentry_sdk .traces .start_span (name = "span" ) as segment :
41+ assert segment ._get_baggage ().sentry_items ["sample_rand" ] == "0.100000"
42+
43+
2844def test_continue_trace_missing_sample_rand ():
2945 """
3046 Test that a missing sample_rand is filled in onto the transaction's baggage.
@@ -41,3 +57,23 @@ def test_continue_trace_missing_sample_rand():
4157 transaction = sentry_sdk .continue_trace (headers )
4258
4359 assert transaction .get_baggage ().sentry_items ["sample_rand" ] == "0.500000"
60+
61+
62+ def test_continue_trace_missing_sample_rand_span_streaming (sentry_init ):
63+ """
64+ Test that a missing sample_rand is filled in onto the segment's baggage.
65+ """
66+
67+ sentry_init (traces_sample_rate = 1.0 , _experiments = {"trace_lifecycle" : "stream" })
68+
69+ headers = {
70+ "sentry-trace" : "00000000000000000000000000000000-0000000000000000" ,
71+ "baggage" : "sentry-placeholder=asdf" ,
72+ }
73+
74+ with mock .patch (
75+ "sentry_sdk.tracing_utils.Random.randrange" , Mock (return_value = 500000 )
76+ ):
77+ sentry_sdk .traces .continue_trace (headers )
78+ with sentry_sdk .traces .start_span (name = "span" ) as span :
79+ assert span ._get_baggage ().sentry_items ["sample_rand" ] == "0.500000"
0 commit comments