ClickhouseDb class.
Why ClickHouse only for traces
ClickHouse is an OLAP columnar engine. It is designed for the workload traces actually produce:- Append-heavy ingest. Spans arrive continuously. ClickHouse inserts coalesce into large columnar parts.
- Time-bucketed aggregates. Trace dashboards group by minute, hour, day. Columnar storage scans only the columns the query touches.
- Low-cardinality filters. Filtering by
statusorspan_kindover billions of rows is whatLowCardinality(String)is built for. Filtering byagent_id/session_idscans one narrow column instead of whole rows. - Cheap retention.
PARTITION BY toYYYYMM(start_time)lets you drop a month of traces with oneALTER TABLE.
Session and memory storage hit all three of those patterns, which is why Agno uses a row-store for them and reserves ClickHouse for tracing.
Usage
Install the required packages:clickhouse_for_traces.py
Run PostgreSQL and ClickHouse
Install Docker Desktop, then start the PostgreSQL row store on port5532:
8123 for HTTP and 9000 for its native protocol:
cookbook/scripts/run_clickhouse.sh.