|
7 | 7 | """ |
8 | 8 |
|
9 | 9 | from unittest import mock |
10 | | -from unittest.mock import Mock |
11 | 10 |
|
12 | 11 | import sentry_sdk |
13 | 12 |
|
14 | 13 |
|
15 | | -def test_continue_trace_with_sample_rand(): |
| 14 | +def test_continue_trace_with_sample_rand(sentry_init): |
16 | 15 | """ |
17 | 16 | Test that an incoming sample_rand is propagated onto the transaction's baggage. |
18 | 17 | """ |
| 18 | + sentry_init() |
| 19 | + |
19 | 20 | headers = { |
20 | 21 | "sentry-trace": "00000000000000000000000000000000-0000000000000000-0", |
21 | 22 | "baggage": "sentry-sample_rand=0.1,sentry-sample_rate=0.5", |
22 | 23 | } |
23 | 24 |
|
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" |
26 | 28 |
|
27 | 29 |
|
28 | | -def test_continue_trace_missing_sample_rand(): |
| 30 | +def test_continue_trace_missing_sample_rand(sentry_init): |
29 | 31 | """ |
30 | 32 | Test that a missing sample_rand is filled in onto the transaction's baggage. |
31 | 33 | """ |
| 34 | + sentry_init() |
32 | 35 |
|
33 | 36 | headers = { |
34 | 37 | "sentry-trace": "00000000000000000000000000000000-0000000000000000", |
35 | 38 | "baggage": "sentry-placeholder=asdf", |
36 | 39 | } |
37 | 40 |
|
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