Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/tracing/test_sample_rand_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
3 changes: 0 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading