From b124ddf62dd2fa3e767197e899bde22acc7d2f15 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 30 Jun 2026 14:44:16 +0200 Subject: [PATCH] test: Add span origin span streaming tests --- tests/tracing/test_span_origin.py | 52 ++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/tests/tracing/test_span_origin.py b/tests/tracing/test_span_origin.py index 5c578c5066..4c4e7ffd1a 100644 --- a/tests/tracing/test_span_origin.py +++ b/tests/tracing/test_span_origin.py @@ -1,12 +1,12 @@ -from sentry_sdk import start_span, start_transaction +import sentry_sdk def test_span_origin_manual(sentry_init, capture_events): sentry_init(traces_sample_rate=1.0) events = capture_events() - with start_transaction(name="hi"): - with start_span(op="foo", name="bar"): + with sentry_sdk.start_transaction(name="hi"): + with sentry_sdk.start_span(op="foo", name="bar"): pass (event,) = events @@ -20,12 +20,12 @@ def test_span_origin_custom(sentry_init, capture_events): sentry_init(traces_sample_rate=1.0) events = capture_events() - with start_transaction(name="hi"): - with start_span(op="foo", name="bar", origin="foo.foo2.foo3"): + with sentry_sdk.start_transaction(name="hi"): + with sentry_sdk.start_span(op="foo", name="bar", origin="foo.foo2.foo3"): pass - with start_transaction(name="ho", origin="ho.ho2.ho3"): - with start_span(op="baz", name="qux", origin="baz.baz2.baz3"): + with sentry_sdk.start_transaction(name="ho", origin="ho.ho2.ho3"): + with sentry_sdk.start_span(op="baz", name="qux", origin="baz.baz2.baz3"): pass (first_transaction, second_transaction) = events @@ -36,3 +36,41 @@ def test_span_origin_custom(sentry_init, capture_events): assert second_transaction["contexts"]["trace"]["origin"] == "ho.ho2.ho3" assert second_transaction["spans"][0]["origin"] == "baz.baz2.baz3" + + +def test_span_origin_manual_span_streaming(sentry_init, capture_items): + sentry_init(_experiments={"trace_lifecycle": "stream"}, traces_sample_rate=1.0) + items = capture_items("span") + + with sentry_sdk.traces.start_span(name="hi"): + pass + + sentry_sdk.flush() + + (span,) = [item.payload for item in items] + + assert len(items) == 1 + assert span["attributes"]["sentry.origin"] == "manual" + + +def test_span_origin_custom_span_streaming(sentry_init, capture_items): + sentry_init(_experiments={"trace_lifecycle": "stream"}, traces_sample_rate=1.0) + items = capture_items("span") + + with sentry_sdk.traces.start_span( + name="hi", attributes={"sentry.origin": "foo.foo2.foo3"} + ): + pass + + with sentry_sdk.traces.start_span( + name="ho", attributes={"sentry.origin": "baz.baz2.baz3"} + ): + pass + + sentry_sdk.flush() + + (span1, span2) = [item.payload for item in items] + + assert len(items) == 2 + assert span1["attributes"]["sentry.origin"] == "foo.foo2.foo3" + assert span2["attributes"]["sentry.origin"] == "baz.baz2.baz3"