Skip to content

Commit 248306f

Browse files
committed
.
1 parent 67ca0e5 commit 248306f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tests/tracing/test_sample_rand_propagation.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,38 @@
77
"""
88

99
from unittest import mock
10-
from unittest.mock import Mock
1110

1211
import sentry_sdk
1312

1413

15-
def test_continue_trace_with_sample_rand():
14+
def test_continue_trace_with_sample_rand(sentry_init):
1615
"""
1716
Test that an incoming sample_rand is propagated onto the transaction's baggage.
1817
"""
18+
sentry_init()
19+
1920
headers = {
2021
"sentry-trace": "00000000000000000000000000000000-0000000000000000-0",
2122
"baggage": "sentry-sample_rand=0.1,sentry-sample_rate=0.5",
2223
}
2324

24-
transaction = sentry_sdk.continue_trace(headers)
25-
assert transaction.get_baggage().sentry_items["sample_rand"] == "0.1"
25+
with sentry_sdk.continue_trace(headers):
26+
with sentry_sdk.start_span(name="root-span") as root_span:
27+
assert root_span.get_baggage().sentry_items["sample_rand"] == "0.1"
2628

2729

28-
def test_continue_trace_missing_sample_rand():
30+
def test_continue_trace_missing_sample_rand(sentry_init):
2931
"""
3032
Test that a missing sample_rand is filled in onto the transaction's baggage.
3133
"""
34+
sentry_init()
3235

3336
headers = {
3437
"sentry-trace": "00000000000000000000000000000000-0000000000000000",
3538
"baggage": "sentry-placeholder=asdf",
3639
}
3740

38-
mock_uniform = Mock(return_value=0.5)
39-
40-
with mock.patch("sentry_sdk.tracing_utils.Random.uniform", mock_uniform):
41-
transaction = sentry_sdk.continue_trace(headers)
42-
43-
assert transaction.get_baggage().sentry_items["sample_rand"] == "0.500000"
41+
with mock.patch("sentry_sdk.tracing_utils.Random.uniform", return_value=0.5):
42+
with sentry_sdk.continue_trace(headers):
43+
with sentry_sdk.start_span(name="root-span") as root_span:
44+
assert root_span.get_baggage().sentry_items["sample_rand"] == "0.500000"

0 commit comments

Comments
 (0)