Query with the CLI
Pass a query as one quoted argument, or use-f, --file <path> to read it from a file:
--csv for CSV, --json for the complete API response, and --output <file> to write the selected format to a file.
{name:Type} placeholders with one --param name=value flag per value. Parameters stay separate from the SQL text.
--json with --csv, or repeating a --param name, exits 2. A table’s row count, and a truncation warning for a table or CSV, go to stderr. With --json, read truncated from the response instead. A file written with --output has no terminal styling.
Run traceroot sql schema to list the available tables, columns, and ClickHouse types. traceroot sql --help lists every flag.
Worked queries
Always include a time predicate onspan_start_time or trace_start_time that compares the column directly with a constant: a timestamp, a parameter, or an expression such as now() - INTERVAL 7 DAY. The gateway uses that range when reading the underlying project-scoped views, so bounded queries scan less data.
Recent error spans
p95 latency by model
Cost by model over seven days
Query with the API
Send a project API key as a bearer token toPOST /api/v1/public/sql:
project_id query parameter.
A successful response contains column names and types, row values in the same order, the returned row count, truncation state, elapsed time, and any read statistics supplied by ClickHouse:
statistics is best-effort and may be empty. When more rows match than the gateway returns, truncated is true. A request’s max_rows can lower the server cap, but cannot raise it.
Fetch the same schema used by the validator and query rewriter with GET /api/v1/public/sql/schema:
Public schema
Queries can reference only two logical tables:
Use
traceroot sql schema --json or GET /api/v1/public/sql/schema for the authoritative column list and types.
These are curated views over traceroot’s internal tables. They deliberately exclude:
- span and trace
inputandoutputpayloads; - the raw metadata JSON document;
metadatais exposed instead as a one-level string map, accessed with expressions such asmetadata['user_id']; project_id,ch_create_time,ch_update_time, and internal classification fields;- rows that are not customer traffic; and
- every trace that belongs to an evaluation run, including its spans.
SQL contract
The gateway accepts oneSELECT or UNION. CTEs, subqueries, joins, grouping, ordering, and the row_number, rank, and dense_rank window functions are supported. Functions are allowlisted; the list includes common aggregation, date-bucketing, string, conversion, conditional, and metadata-map functions. A ClickHouse function outside the allowlist is rejected even if ClickHouse normally supports it.
The gateway rejects:
- multiple statements, writes, DDL, and control statements;
- tables other than
spansandtraces, including table functions; - database-qualified names and the internal view names;
FINAL,SETTINGS, andFORMATclauses;- any reference or alias named
project_id; - a CTE named
spansortraces; - a
WHEREthat filters onspan_start_timeortrace_start_timein any other form than a direct comparison with a constant (>=,>,<,<=,=, orBETWEEN), joined to the rest of the clause byAND; and - parameter names
project_idor beginning withscope_, which are reserved for server-side scoping.
How far back a query reaches
Queries only see traces and spans inside your plan’s retention window: 15 days on Free, 30 days on Starter, 90 days on Pro, and no limit on Enterprise. Older rows are left out of the result silently, without an error. Data is not deleted, so upgrading your plan makes older rows readable again.Execution and rate limits
Default execution limits are:
The gateway reserves a row beyond the returned result to detect truncation. If that row exists, it removes the sentinel and returns
truncated: true. Queries that exceed the time, result-size, or memory limits fail; narrow the selected columns or time range and retry.
On self-hosted deployments, operators can change the four ClickHouse caps with CLICKHOUSE_SQL_MAX_EXECUTION_TIME, CLICKHOUSE_SQL_MAX_RESULT_ROWS, CLICKHOUSE_SQL_MAX_RESULT_BYTES, and CLICKHOUSE_SQL_MAX_MEMORY_USAGE.
Concurrency is not a queue. If either per-process slot limit is full, the API returns HTTP 429 with Too many queries are running. Retry shortly. and a one-second Retry-After header.
traceroot Cloud also applies a per-project SQL request rate:
SQL rate limiting is disabled on self-hosted deployments where billing is disabled.