Skip to content

Commit 7581696

Browse files
committed
More fetch_normalized_spans
1 parent cb0eb8e commit 7581696

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

Diff for: tests/test_tracing.py

+49-44
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def simple_tracing():
5454
x = trace("test")
5555
x.start()
5656

57-
span_1 = agent_span(name="agent_1", parent=x)
57+
span_1 = agent_span(name="agent_1", span_id="span_1", parent=x)
5858
span_1.start()
5959
span_1.finish()
6060

@@ -73,33 +73,36 @@ def simple_tracing():
7373
def test_simple_tracing() -> None:
7474
simple_tracing()
7575

76-
spans, traces = fetch_ordered_spans(), fetch_traces()
77-
assert len(spans) == 3
78-
assert len(traces) == 1
79-
80-
trace = traces[0]
81-
standard_trace_checks(trace, name_check="test")
82-
trace_id = trace.trace_id
83-
84-
first_span = spans[0]
85-
standard_span_checks(first_span, trace_id=trace_id, parent_id=None, span_type="agent")
86-
assert first_span.span_data.name == "agent_1"
87-
88-
second_span = spans[1]
89-
standard_span_checks(second_span, trace_id=trace_id, parent_id=None, span_type="custom")
90-
assert second_span.span_id == "span_2"
91-
assert second_span.span_data.name == "custom_1"
92-
93-
third_span = spans[2]
94-
standard_span_checks(
95-
third_span, trace_id=trace_id, parent_id=second_span.span_id, span_type="custom"
76+
assert fetch_normalized_spans(keep_span_id=True) == snapshot(
77+
[
78+
{
79+
"workflow_name": "test",
80+
"children": [
81+
{
82+
"type": "agent",
83+
"id": "span_1",
84+
"data": {"name": "agent_1"},
85+
},
86+
{
87+
"type": "custom",
88+
"id": "span_2",
89+
"data": {"name": "custom_1", "data": {}},
90+
"children": [
91+
{
92+
"type": "custom",
93+
"id": "span_3",
94+
"data": {"name": "custom_2", "data": {}},
95+
}
96+
],
97+
},
98+
],
99+
}
100+
]
96101
)
97-
assert third_span.span_id == "span_3"
98-
assert third_span.span_data.name == "custom_2"
99102

100103

101104
def ctxmanager_spans():
102-
with trace(workflow_name="test", trace_id="123", group_id="456"):
105+
with trace(workflow_name="test", trace_id="trace_123", group_id="456"):
103106
with custom_span(name="custom_1", span_id="span_1"):
104107
with custom_span(name="custom_2", span_id="span_1_inner"):
105108
pass
@@ -111,27 +114,29 @@ def ctxmanager_spans():
111114
def test_ctxmanager_spans() -> None:
112115
ctxmanager_spans()
113116

114-
spans, traces = fetch_ordered_spans(), fetch_traces()
115-
assert len(spans) == 3
116-
assert len(traces) == 1
117-
118-
trace = traces[0]
119-
standard_trace_checks(trace, name_check="test")
120-
trace_id = trace.trace_id
121-
122-
first_span = spans[0]
123-
standard_span_checks(first_span, trace_id=trace_id, parent_id=None, span_type="custom")
124-
assert first_span.span_id == "span_1"
125-
126-
first_inner_span = spans[1]
127-
standard_span_checks(
128-
first_inner_span, trace_id=trace_id, parent_id=first_span.span_id, span_type="custom"
117+
assert fetch_normalized_spans(keep_span_id=True) == snapshot(
118+
[
119+
{
120+
"workflow_name": "test",
121+
"group_id": "456",
122+
"children": [
123+
{
124+
"type": "custom",
125+
"id": "span_1",
126+
"data": {"name": "custom_1", "data": {}},
127+
"children": [
128+
{
129+
"type": "custom",
130+
"id": "span_1_inner",
131+
"data": {"name": "custom_2", "data": {}},
132+
}
133+
],
134+
},
135+
{"type": "custom", "id": "span_2", "data": {"name": "custom_2", "data": {}}},
136+
],
137+
}
138+
]
129139
)
130-
assert first_inner_span.span_id == "span_1_inner"
131-
132-
second_span = spans[2]
133-
standard_span_checks(second_span, trace_id=trace_id, parent_id=None, span_type="custom")
134-
assert second_span.span_id == "span_2"
135140

136141

137142
async def run_subtask(span_id: str | None = None) -> None:

0 commit comments

Comments
 (0)