Each statement below runs as written with langwatch query "<statement>" or in the sql field of POST /api/v1/query. The one exception is the judgments statement, which has a {run:String} parameter that needs a value.
If your key reaches several projects, also name them: add --projects <id,id> or --projects all to the command, or send projects in the body.
Every one filters on its view's time column, because that filter is what keeps the read small: without it the query reads every partition your project has.
Traces: the most recent failures
traces has one row per trace, and its time column is OccurredAt.
SELECT TraceId, TraceName, OccurredAt, TotalDurationMsFROM tracesWHERE OccurredAt >= subtractDays(now(), 1) AND ContainsErrorStatusORDER BY OccurredAt DESCLIMIT 100For latency, use quantile on the same view:
SELECT quantile(0.5)(TotalDurationMs) AS p50_ms, quantile(0.95)(TotalDurationMs) AS p95_ms, quantile(0.99)(TotalDurationMs) AS p99_msFROM tracesWHERE OccurredAt >= subtractDays(now(), 7)Spans: the slowest span in each trace
spans has one row per span, and its time column is StartTime. When you join two views, filter the time column on both sides, because the join key does not narrow the read.
SELECT t.TraceId AS TraceId, t.TraceName AS TraceName, count() AS spans, max(s.DurationMs) AS slowest_span_msFROM traces AS tINNER JOIN spans AS s ON s.TenantId = t.TenantId AND s.TraceId = t.TraceIdWHERE t.OccurredAt >= subtractDays(now(), 1) AND s.StartTime >= subtractDays(now(), 1)GROUP BY TraceId, TraceNameORDER BY slowest_span_ms DESCLIMIT 50Evaluations: pass rate per evaluator
evaluations has one row per evaluator result, and its time column is ScheduledAt. Filter on Status = 'processed' to leave out scheduled, skipped and errored rows. Passed is also empty for evaluators that return only a score, so the rate divides by the rows that have a verdict, countIf(Passed IS NOT NULL), not by count().
SELECT EvaluatorName, count() AS evaluations, countIf(Passed = 1) AS passed, countIf(Passed = 1) / countIf(Passed IS NOT NULL) AS pass_rateFROM evaluationsWHERE ScheduledAt >= subtractDays(now(), 7) AND Status = 'processed'GROUP BY EvaluatorNameORDER BY evaluations DESCLIMIT 50Simulations: runs that failed
simulations has one row per scenario run, and its time column is StartedAt.
SELECT ScenarioRunId, Name, Verdict, StartedAtFROM simulationsWHERE StartedAt >= subtractDays(now(), 7) AND Verdict = 'failure'ORDER BY StartedAt DESCLIMIT 50Rollups: traffic per hour and cost per model
trace_metrics_by_minute and model_usage_by_minute hold one row per minute that is already summed, so a count or a sum over time reads far less here than over traces. Every measure is a sum, so divide by a count when you want an average: TraceCount on trace_metrics_by_minute, SpanCount on model_usage_by_minute, which has no TraceCount. Their time column is BucketStart.
SELECT toStartOfHour(BucketStart) AS hour, sum(TraceCount) AS traces, sum(ErrorCount) AS errorsFROM trace_metrics_by_minuteWHERE BucketStart >= subtractDays(now(), 2)GROUP BY hourORDER BY hourCost columns need the cost:view permission on your key:
SELECT Model, sum(CostSum) AS cost_usd, sum(PromptTokensSum + CompletionTokensSum) AS tokensFROM model_usage_by_minuteWHERE BucketStart >= subtractDays(now(), 7)GROUP BY ModelORDER BY cost_usd DESCLIMIT 50Conversations: the longest ones of the week
There is no conversations view. A conversation is the group of traces that share a ConversationId, and trace_metrics is the view that has that column, along with UserId, CustomerId and HasError.
SELECT ConversationId, count() AS turns, min(OccurredAt) AS started_at, max(OccurredAt) AS last_turnFROM trace_metricsWHERE OccurredAt >= subtractDays(now(), 7) AND ConversationId != ''GROUP BY ConversationIdORDER BY turns DESCLIMIT 50Coding-agent sessions: sessions per agent and repository
coding_sessions has one row per coding-agent session, and its time column is StartedAt.
SELECT Agent, RepositoryName, count() AS sessionsFROM coding_sessionsWHERE StartedAt >= subtractDays(now(), 7)GROUP BY Agent, RepositoryNameORDER BY sessions DESCLIMIT 50Judgments: Instant Eval verdicts per question
judgments has one row per Instant Eval run, trace and question, and its time column is CreatedAt. Rows with Status skipped or failed have no verdict, so the statement keeps only judged rows. Bind the run id as a parameter. With the CLI, add --param run=<run-id>. With REST, add "parameters": {"run": "<run-id>"} to the request body.
SELECT QuestionId, sum(Passed) AS yes, count() AS judgedFROM judgmentsWHERE RunId = {run:String} AND Status = 'judged' AND CreatedAt >= subtractDays(now(), 7)GROUP BY QuestionIdORDER BY QuestionIdTo read verdicts next to trace data, join judgments to traces on TraceId, as in Reading the results.
Also check: langwatch query examples prints more worked statements, and the Query API reference lists every view and column.