More fetch_normalized_spans

This commit is contained in:
Alex Hall 2025-03-21 18:14:59 +02:00
parent 7581696b38
commit 153f703211

View file

@ -224,7 +224,7 @@ async def test_complex_async_tracing() -> None:
def spans_with_setters(): def spans_with_setters():
with trace(workflow_name="test", trace_id="123", group_id="456"): with trace(workflow_name="test", trace_id="trace_123", group_id="456"):
with agent_span(name="agent_1") as span_a: with agent_span(name="agent_1") as span_a:
span_a.span_data.name = "agent_2" span_a.span_data.name = "agent_2"
@ -242,34 +242,33 @@ def spans_with_setters():
def test_spans_with_setters() -> None: def test_spans_with_setters() -> None:
spans_with_setters() spans_with_setters()
spans, traces = fetch_ordered_spans(), fetch_traces() assert fetch_normalized_spans() == snapshot(
assert len(spans) == 4 [
assert len(traces) == 1 {
"workflow_name": "test",
trace = traces[0] "group_id": "456",
standard_trace_checks(trace, name_check="test") "children": [
trace_id = trace.trace_id {
"type": "agent",
# Check the spans "data": {"name": "agent_2"},
first_span = spans[0] "children": [
standard_span_checks(first_span, trace_id=trace_id, parent_id=None, span_type="agent") {
assert first_span.span_data.name == "agent_2" "type": "function",
"data": {"name": "function_1", "input": "i", "output": "o"},
second_span = spans[1] },
standard_span_checks( {
second_span, trace_id=trace_id, parent_id=first_span.span_id, span_type="function" "type": "generation",
) "data": {"input": [{"foo": "bar"}]},
assert second_span.span_data.input == "i" },
assert second_span.span_data.output == "o" {
"type": "handoff",
third_span = spans[2] "data": {"from_agent": "agent_1", "to_agent": "agent_2"},
standard_span_checks( },
third_span, trace_id=trace_id, parent_id=first_span.span_id, span_type="generation" ],
) }
],
fourth_span = spans[3] }
standard_span_checks( ]
fourth_span, trace_id=trace_id, parent_id=first_span.span_id, span_type="handoff"
) )