diff --git a/tests/tracing/test_sample_rand_propagation.py b/tests/tracing/test_sample_rand_propagation.py index e6f3e99510..68a634f942 100644 --- a/tests/tracing/test_sample_rand_propagation.py +++ b/tests/tracing/test_sample_rand_propagation.py @@ -25,6 +25,22 @@ def test_continue_trace_with_sample_rand(): assert transaction.get_baggage().sentry_items["sample_rand"] == "0.1" +def test_continue_trace_with_sample_rand_span_streaming(sentry_init): + """ + Test that an incoming sample_rand is propagated onto the segment's baggage. + """ + sentry_init(traces_sample_rate=1.0, _experiments={"trace_lifecycle": "stream"}) + + headers = { + "sentry-trace": "00000000000000000000000000000000-0000000000000000-1", + "baggage": "sentry-sample_rand=0.100000,sentry-sample_rate=0.5", + } + + sentry_sdk.traces.continue_trace(headers) + with sentry_sdk.traces.start_span(name="span") as segment: + assert segment._get_baggage().sentry_items["sample_rand"] == "0.100000" + + def test_continue_trace_missing_sample_rand(): """ 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(): transaction = sentry_sdk.continue_trace(headers) assert transaction.get_baggage().sentry_items["sample_rand"] == "0.500000" + + +def test_continue_trace_missing_sample_rand_span_streaming(sentry_init): + """ + Test that a missing sample_rand is filled in onto the segment's baggage. + """ + + sentry_init(traces_sample_rate=1.0, _experiments={"trace_lifecycle": "stream"}) + + headers = { + "sentry-trace": "00000000000000000000000000000000-0000000000000000", + "baggage": "sentry-placeholder=asdf", + } + + with mock.patch( + "sentry_sdk.tracing_utils.Random.randrange", Mock(return_value=500000) + ): + sentry_sdk.traces.continue_trace(headers) + with sentry_sdk.traces.start_span(name="span") as span: + assert span._get_baggage().sentry_items["sample_rand"] == "0.500000" diff --git a/uv.lock b/uv.lock index 855c128ef8..fb1818bba8 100644 --- a/uv.lock +++ b/uv.lock @@ -6,9 +6,6 @@ resolution-markers = [ "python_full_version < '3.15'", ] -[options] -prerelease-mode = "allow" - [manifest] [manifest.dependency-groups]