Skip to content

Commit 2e09497

Browse files
authored
test: Add streaming tests to test_http_headers (getsentry#6785)
### Description Add span streaming variants to tests in `test_http_headers` #### Issues Part of getsentry#5395 #### Reminders - Please add tests to validate your changes, and lint your code using `uv run ruff`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr)
1 parent 9996734 commit 2e09497

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/tracing/test_http_headers.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pytest
44

5+
import sentry_sdk
6+
from sentry_sdk.traces import StreamedSpan
57
from sentry_sdk.tracing import Transaction
68
from sentry_sdk.tracing_utils import extract_sentrytrace_data
79

@@ -26,6 +28,35 @@ def test_to_traceparent(sampled):
2628
assert parts[2] == "1" if sampled is True else "0" # sampled
2729

2830

31+
@pytest.mark.parametrize("traces_sample_rate", [1.0, 0.0, None])
32+
def test_to_traceparent_span_streaming(sentry_init, traces_sample_rate):
33+
sentry_init(
34+
traces_sample_rate=traces_sample_rate,
35+
_experiments={
36+
"trace_lifecycle": "stream",
37+
},
38+
)
39+
40+
with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span:
41+
traceparent = sentry_sdk.get_traceparent()
42+
43+
parts = traceparent.split("-")
44+
if traces_sample_rate is None:
45+
propagation_context = (
46+
sentry_sdk.get_current_scope().get_active_propagation_context()
47+
)
48+
assert parts[0] == propagation_context.trace_id # trace_id
49+
assert parts[1] == propagation_context.span_id # parent_span_id
50+
assert len(parts) == 2
51+
else:
52+
assert parts[0] == span.trace_id # trace_id
53+
assert parts[1] == span.span_id # parent_span_id
54+
if traces_sample_rate == 1.0:
55+
assert parts[2] == "1"
56+
else:
57+
assert parts[2] == "0"
58+
59+
2960
@pytest.mark.parametrize("sampling_decision", [True, False])
3061
def test_sentrytrace_extraction(sampling_decision):
3162
sentrytrace_header = "12312012123120121231201212312012-0415201309082013-{}".format(
@@ -75,3 +106,24 @@ def test_iter_headers(monkeypatch):
75106
assert (
76107
headers["sentry-trace"] == "12312012123120121231201212312012-0415201309082013-0"
77108
)
109+
110+
111+
def test_iter_headers_span_streaming(sentry_init, monkeypatch):
112+
sentry_init(
113+
traces_sample_rate=0.0,
114+
_experiments={
115+
"trace_lifecycle": "stream",
116+
},
117+
)
118+
monkeypatch.setattr(
119+
StreamedSpan,
120+
"_to_traceparent",
121+
mock.Mock(return_value="12312012123120121231201212312012-0415201309082013-0"),
122+
)
123+
124+
with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span:
125+
headers = dict(span._iter_headers())
126+
assert (
127+
headers["sentry-trace"]
128+
== "12312012123120121231201212312012-0415201309082013-0"
129+
)

0 commit comments

Comments
 (0)