SQL editor

Query recorded spans, inspect results, and reuse saved queries.

Open Observability → SQL editor to query your recorded spans with read-only ClickHouse SQL. Use the logs table to compare models, investigate cost and latency, or answer questions beyond the standard span filters.

Run your first query

  1. Click New query.
  2. Click the arrow beside New query and choose Top models.
  3. Review the SQL, then click Run. On macOS, the displayed shortcut is ⌘ Enter.
  4. Read the returned table below the editor. The result summary shows the row count and execution time.

The Top models example groups recorded rows by model:

SELECT
model,
count(*) AS requests,
avg(cost) AS avg_cost,
avg(latency) AS avg_latency
FROM logs
GROUP BY model
ORDER BY requests DESC
LIMIT 20

The requests column counts the recorded rows for each model. avg_cost and avg_latency show their average recorded cost and latency. The query returns up to 20 model groups, ordered by row count.

Full SQL editor page with the saved-query list, Top models SQL, Run button, and two populated result rows.
Run a query and inspect its returned columns, row count, and execution time below the editor.

Screenshots use the Respan demo. Your results depend on your recorded data. The logs table contains recorded spans. A trace can contain multiple spans, so counting rows is different from counting complete traces. The example’s requests alias names that row count.

Start from an example

Use the example menu to load SQL for a common investigation, then adapt its fields, conditions, or grouping to your question.

InvestigateExamples
Model usageTop models
CostCost by day, Cost per customer
LatencyP95 latency
ErrorsError rate
TokensToken usage (hourly)
TracesTraces overview
Evaluation resultsEval scores by evaluator
Multi-step queriesCTE: model summary, CTE: cost vs latency by model, CTE: daily cost by top models
Full SQL editor page with the built-in example menu open above the populated Top models query and results.
Choose a built-in example as a starting point for your investigation.

Narrow the query with SQL

Put conditions in the query’s WHERE clause. For example, add this line after FROM logs and before GROUP BY model to limit the Top models query to the last seven days:

WHERE timestamp >= now() - INTERVAL 7 DAY

Run the query again after changing it. The result table reflects the last execution, so check the SQL before interpreting the returned values.

Save and reopen a query

Give a useful query a descriptive name so it is easy to find again:

  1. Click the query title above the editor.
  2. Enter a name and, optionally, a description of the question it answers.
  3. Click Save in the query details panel.
Full SQL editor page with the query-name and optional-description panel open, its Save button visible, and populated results beneath it.
Name a query and add an optional description so you can recognize it later.

Running a new query can create an Untitled query in the saved-query list. Use Save after editing a query; on macOS, the editor shows ⌘ S as its shortcut.

Select a saved query from the list to restore its SQL and description. Click Run to fetch results again.

Export results

After a query returns results, open Export above the result table and choose Download as CSV or Download as JSON. Export is disabled in the public demo; use your project on the Respan platform to download results.

Troubleshooting

The query returns no rows

Check the query’s conditions against the data you have recorded. A short time window or a specific model condition can exclude all matching spans. Widen the interval or remove one condition at a time, then run the query again.

A field is unknown

Check its spelling and the table used by the query. Start from the closest built-in example, keep its field names, and change one part at a time.

The query covers too much data

Add a timestamp condition and select only the fields needed for the investigation. For aggregates, narrow the input rows with WHERE before grouping them. LIMIT controls how many result rows are returned; it does not replace a filter on the records being analyzed.