docs(tracing): fix custom span output example (#4196)

This commit is contained in:
Sam Xie
2026-08-04 22:19:06 -07:00
committed by GitHub
parent d270dac3a5
commit 8be468f35b
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ class Span(abc.ABC, Generic[TSpanData]):
"table": "users"
}) as span:
results = await db.query("SELECT * FROM users")
span.set_output({"count": len(results)})
span.span_data.data["output"] = {"count": len(results)}
# Handling errors in spans
with custom_span("risky_operation") as span:
+18
View File
@@ -273,6 +273,24 @@ def test_spans_with_setters() -> None:
)
def test_custom_span_records_output_in_data() -> None:
with trace(workflow_name="test"):
with custom_span("database_query", {"operation": "SELECT", "table": "users"}) as span:
span.span_data.data["output"] = {"count": 2}
exported = span.export()
assert exported is not None
assert exported["span_data"] == {
"type": "custom",
"name": "database_query",
"data": {
"operation": "SELECT",
"table": "users",
"output": {"count": 2},
},
}
def disabled_tracing():
with trace(workflow_name="test", trace_id="123", group_id="456", disabled=True):
with agent_span(name="agent_1"):