Skip to content

Commit 19c9847

Browse files
committed
test: Add streaming tests to test_http_headers
1 parent 07d8eb8 commit 19c9847

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

tests/tracing/test_http_headers.py

Lines changed: 49 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,32 @@ 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+
assert parts[2] == "1" if traces_sample_rate == 1.0 else "0" # sampled
55+
56+
2957
@pytest.mark.parametrize("sampling_decision", [True, False])
3058
def test_sentrytrace_extraction(sampling_decision):
3159
sentrytrace_header = "12312012123120121231201212312012-0415201309082013-{}".format(
@@ -75,3 +103,24 @@ def test_iter_headers(monkeypatch):
75103
assert (
76104
headers["sentry-trace"] == "12312012123120121231201212312012-0415201309082013-0"
77105
)
106+
107+
108+
def test_iter_headers_span_streaming(sentry_init, monkeypatch):
109+
sentry_init(
110+
traces_sample_rate=0.0,
111+
_experiments={
112+
"trace_lifecycle": "stream",
113+
},
114+
)
115+
monkeypatch.setattr(
116+
StreamedSpan,
117+
"_to_traceparent",
118+
mock.Mock(return_value="12312012123120121231201212312012-0415201309082013-0"),
119+
)
120+
121+
with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span:
122+
headers = dict(span._iter_headers())
123+
assert (
124+
headers["sentry-trace"]
125+
== "12312012123120121231201212312012-0415201309082013-0"
126+
)

0 commit comments

Comments
 (0)