Skip to contentSkip to page list

Docs

npx langwatch

Trace any coding agent · Setup guide →

LangWatchQL first queries: one example per view

Worked LangWatchQL statements for traces, spans, evaluations, simulations, per-minute rollups, conversations, coding-agent sessions and Instant Eval judgments.

On this page

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.

example.sqlSQL
SELECT TraceId, TraceName, OccurredAt, TotalDurationMsFROM tracesWHERE OccurredAt >= subtractDays(now(), 1)  AND ContainsErrorStatusORDER BY OccurredAt DESCLIMIT 100

For latency, use quantile on the same view:

example.sqlSQL
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.

example.sqlSQL
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 50

Evaluations: 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().

example.sqlSQL
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 50

Simulations: runs that failed

simulations has one row per scenario run, and its time column is StartedAt.

example.sqlSQL
SELECT ScenarioRunId, Name, Verdict, StartedAtFROM simulationsWHERE StartedAt >= subtractDays(now(), 7)  AND Verdict = 'failure'ORDER BY StartedAt DESCLIMIT 50

Rollups: 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.

example.sqlSQL
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 hour

Cost columns need the cost:view permission on your key:

example.sqlSQL
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 50

Conversations: 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.

example.sqlSQL
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 50

Coding-agent sessions: sessions per agent and repository

coding_sessions has one row per coding-agent session, and its time column is StartedAt.

example.sqlSQL
SELECT  Agent,  RepositoryName,  count() AS sessionsFROM coding_sessionsWHERE StartedAt >= subtractDays(now(), 7)GROUP BY Agent, RepositoryNameORDER BY sessions DESCLIMIT 50

Judgments: 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.

example.sqlSQL
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 QuestionId

To 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.

Documentation