Skip to content

Commit 42b5141

Browse files
committed
test: Add streaming sample_rand propagation tests
1 parent e2dd162 commit 42b5141

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

tests/tracing/test_sample_rand_propagation.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2844
def 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"

uv.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)