Skip to content

Commit b124ddf

Browse files
committed
test: Add span origin span streaming tests
1 parent 4abb01f commit b124ddf

1 file changed

Lines changed: 45 additions & 7 deletions

File tree

tests/tracing/test_span_origin.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from sentry_sdk import start_span, start_transaction
1+
import sentry_sdk
22

33

44
def test_span_origin_manual(sentry_init, capture_events):
55
sentry_init(traces_sample_rate=1.0)
66
events = capture_events()
77

8-
with start_transaction(name="hi"):
9-
with start_span(op="foo", name="bar"):
8+
with sentry_sdk.start_transaction(name="hi"):
9+
with sentry_sdk.start_span(op="foo", name="bar"):
1010
pass
1111

1212
(event,) = events
@@ -20,12 +20,12 @@ def test_span_origin_custom(sentry_init, capture_events):
2020
sentry_init(traces_sample_rate=1.0)
2121
events = capture_events()
2222

23-
with start_transaction(name="hi"):
24-
with start_span(op="foo", name="bar", origin="foo.foo2.foo3"):
23+
with sentry_sdk.start_transaction(name="hi"):
24+
with sentry_sdk.start_span(op="foo", name="bar", origin="foo.foo2.foo3"):
2525
pass
2626

27-
with start_transaction(name="ho", origin="ho.ho2.ho3"):
28-
with start_span(op="baz", name="qux", origin="baz.baz2.baz3"):
27+
with sentry_sdk.start_transaction(name="ho", origin="ho.ho2.ho3"):
28+
with sentry_sdk.start_span(op="baz", name="qux", origin="baz.baz2.baz3"):
2929
pass
3030

3131
(first_transaction, second_transaction) = events
@@ -36,3 +36,41 @@ def test_span_origin_custom(sentry_init, capture_events):
3636

3737
assert second_transaction["contexts"]["trace"]["origin"] == "ho.ho2.ho3"
3838
assert second_transaction["spans"][0]["origin"] == "baz.baz2.baz3"
39+
40+
41+
def test_span_origin_manual_span_streaming(sentry_init, capture_items):
42+
sentry_init(_experiments={"trace_lifecycle": "stream"}, traces_sample_rate=1.0)
43+
items = capture_items("span")
44+
45+
with sentry_sdk.traces.start_span(name="hi"):
46+
pass
47+
48+
sentry_sdk.flush()
49+
50+
(span,) = [item.payload for item in items]
51+
52+
assert len(items) == 1
53+
assert span["attributes"]["sentry.origin"] == "manual"
54+
55+
56+
def test_span_origin_custom_span_streaming(sentry_init, capture_items):
57+
sentry_init(_experiments={"trace_lifecycle": "stream"}, traces_sample_rate=1.0)
58+
items = capture_items("span")
59+
60+
with sentry_sdk.traces.start_span(
61+
name="hi", attributes={"sentry.origin": "foo.foo2.foo3"}
62+
):
63+
pass
64+
65+
with sentry_sdk.traces.start_span(
66+
name="ho", attributes={"sentry.origin": "baz.baz2.baz3"}
67+
):
68+
pass
69+
70+
sentry_sdk.flush()
71+
72+
(span1, span2) = [item.payload for item in items]
73+
74+
assert len(items) == 2
75+
assert span1["attributes"]["sentry.origin"] == "foo.foo2.foo3"
76+
assert span2["attributes"]["sentry.origin"] == "baz.baz2.baz3"

0 commit comments

Comments
 (0)