From 19c9847823048b07cf798ae026dd4f8ca3509a98 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 8 Jul 2026 15:48:29 +0200 Subject: [PATCH] test: Add streaming tests to test_http_headers --- tests/tracing/test_http_headers.py | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/tracing/test_http_headers.py b/tests/tracing/test_http_headers.py index 1914347b2b..161bee58de 100644 --- a/tests/tracing/test_http_headers.py +++ b/tests/tracing/test_http_headers.py @@ -2,6 +2,8 @@ import pytest +import sentry_sdk +from sentry_sdk.traces import StreamedSpan from sentry_sdk.tracing import Transaction from sentry_sdk.tracing_utils import extract_sentrytrace_data @@ -26,6 +28,32 @@ def test_to_traceparent(sampled): assert parts[2] == "1" if sampled is True else "0" # sampled +@pytest.mark.parametrize("traces_sample_rate", [1.0, 0.0, None]) +def test_to_traceparent_span_streaming(sentry_init, traces_sample_rate): + sentry_init( + traces_sample_rate=traces_sample_rate, + _experiments={ + "trace_lifecycle": "stream", + }, + ) + + with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span: + traceparent = sentry_sdk.get_traceparent() + + parts = traceparent.split("-") + if traces_sample_rate is None: + propagation_context = ( + sentry_sdk.get_current_scope().get_active_propagation_context() + ) + assert parts[0] == propagation_context.trace_id # trace_id + assert parts[1] == propagation_context.span_id # parent_span_id + assert len(parts) == 2 + else: + assert parts[0] == span.trace_id # trace_id + assert parts[1] == span.span_id # parent_span_id + assert parts[2] == "1" if traces_sample_rate == 1.0 else "0" # sampled + + @pytest.mark.parametrize("sampling_decision", [True, False]) def test_sentrytrace_extraction(sampling_decision): sentrytrace_header = "12312012123120121231201212312012-0415201309082013-{}".format( @@ -75,3 +103,24 @@ def test_iter_headers(monkeypatch): assert ( headers["sentry-trace"] == "12312012123120121231201212312012-0415201309082013-0" ) + + +def test_iter_headers_span_streaming(sentry_init, monkeypatch): + sentry_init( + traces_sample_rate=0.0, + _experiments={ + "trace_lifecycle": "stream", + }, + ) + monkeypatch.setattr( + StreamedSpan, + "_to_traceparent", + mock.Mock(return_value="12312012123120121231201212312012-0415201309082013-0"), + ) + + with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span: + headers = dict(span._iter_headers()) + assert ( + headers["sentry-trace"] + == "12312012123120121231201212312012-0415201309082013-0" + )