feat(tracing): fetch all span input/output in one query for exports

This commit is contained in:
Ishaan Jaff 2026-09-30 08:07:57 -07:00
parent 3ce7c13cc2
commit 66db6ec124
No known key found for this signature in database

View file

@ -117,6 +117,12 @@ ORDER BY o.Timestamp, abs(toUnixTimestamp64Milli(s.start_time) - toUnixTimestamp
LIMIT 1 BY o.SpanId
"""
TRACE_IO_SQL: Final = f"""
SELECT SpanId AS span_id, Input AS input, Output AS output
FROM {OTEL_TRACES_TABLE}
WHERE TraceId = {{trace_id:String}} AND {_SCOPE_OTEL}
"""
SPAN_DETAIL_SQL: Final = f"""
SELECT SpanId AS span_id, Input AS input, Output AS output, SpanAttributes AS attributes
FROM {OTEL_TRACES_TABLE}
@ -341,3 +347,8 @@ class ClickHouseTraceStore:
output=rows[0]["output"],
attributes=dict(rows[0]["attributes"]),
)
async def get_span_io(self, trace_id: str, scope: TraceScope) -> dict[str, tuple[str, str]]:
"""span_id -> (input, output) for every span in the trace, in one query (for exports)."""
rows = await self.client.query(TRACE_IO_SQL, {**scope, "trace_id": trace_id})
return {r["span_id"]: (r["input"], r["output"]) for r in rows}