A first query
The 10 routes with the most 5xx responses in the last hour:struct telemetry query --file query.json --json or the query_telemetry MCP tool. Struct checks each field and metric name the document uses against the telemetry your workspace sent in the last 7 days, and every error says how to fix the document. A name Struct can’t check within 2 seconds is listed in namesUnchecked (names_unchecked from the MCP tool) with the reason, and the query runs anyway; the CLI names it on stderr. Before you read an empty result as no data, confirm those names with struct telemetry describe.Find real names first. Do not guess them:struct telemetry guide prints a compact guide, and struct telemetry guide top_n prints a worked example.Document
Queries
Fields
The instrumentation scope fields
scope.name and scope.version are also standard for all three signals. Any other name is an attribute, so http.route reads the span attribute http.route. attributes.<key> is always an attribute and resource.<key> is always a resource attribute.Filters
Negate a whole expression with
NOT (duration > 2000) or NOT hasAny(tags, ['a', 'b']); keyword operators also accept forms such as kind NOT IN ('server', 'consumer'). In logs, a bare quoted string searches the body: 'timeout'. NOT binds tighter than AND, and AND tighter than OR, so write a AND (b OR c).Metrics
time reduces each series over the range, and space combines the series in each group. A metric’s value is in its own unit. struct telemetry describe metrics --field <name> --json lists a metric’s type and labels.Histogram
max and min require delta temporality and recorded, non-negative minimum and maximum values. Otherwise, the query is refused; use a percentile or avg instead. Check temporality with struct telemetry describe metrics --field <name> --json.Formulas
Error rate per route, as a percentage:+ - * /, parentheses, numbers, query and formula names, abs(), min(x, y), max(x, y) and now(). unit is required and declares the result’s unit; nothing is converted. Queries in a formula use the same groupBy, or none.Where a query has no row for a group, count(), count_distinct() and rate() read 0. Anything else has no value, so the formula has no value there. Division by zero has no value.Results
raw, distribution and fields require a traces or logs output query. A metrics output returns ok: false and CLI query_invalid; use scalar, table or time_series for metrics instead.For scalar, table and time_series, output can list several names sharing a groupBy, to return them side by side:ok, errors, result and plan, which says where each query read from. It returns at most 200 rows or points. When there are more, truncated is true, and total_<key> gives the count when Struct knows it.Read the next page
Araw or table result that was cut, by the query’s limit or by the 200-row response, has nextCursor. Run the same document again with that value as cursor in one of its queries:nextCursor. Each page starts after the last row the previous one returned, so no row is skipped or repeated. If a result has truncated: true without nextCursor, more rows matched but continuation is unavailable; narrow the filter or range to retrieve them.- Change nothing but
cursor. A cursor works only with the document that returned it; with another filter, order, limit or range the response isok: falseand says so. - Every page reads the first page’s time range. With
"range": {"last": "1h"}, the hour ends when the first page ran, however much later the next page runs. - A table computes its groups again for each page. One ordered by a value, such as a count, pages exactly while those values stay the same; if new data changes them between pages, a group near a page boundary can be skipped or repeated. Order by the group field, or use a range that has ended, when that matters.
- The cursor is opaque text. Don’t build or edit one.
raw and table results have pages. For other results, narrow the range or add filters.Use one query’s groups in another
field IN query('Q') keeps rows whose field is one of query Q’s group values. What the checkout service logged during its slow requests:Q groups by exactly one field, of the same type as field, and uses no semijoin itself. NOT IN query('Q') keeps the rows outside Q’s groups.Read one record in full
Long field values in query results are cut short. To read a row in full, run araw query with "select": ["*"]: every stored column, such as SpanAttributes, Events.* and Links.* for a span or Body and LogAttributes for a log, each value up to 100,000 characters. "*" stands alone in select."signal": "logs". To read one log row again, filter by the id a raw logs row returns: "filter": "id = 'ROW_ID'". The CLI does both:span looks back 24 hours and log 1 hour by default; pass --since (at most 30 days) for an older span, and --at TIMESTAMP (the row’s timestamp) for an older log row. A log lookup by id reads every log in its range, so keep that range narrow: a few hours, not days.What the language can’t express
- Fields of logs and spans combined in one row. Run two queries, or use
IN query('Q')to link them. - Grouping by a computed value, such as a regular expression’s capture. Match the known values with
REGEXPorCONTAINSin separate queries. - Funnels and sequences, and spans and logs in one timeline.
- Time windows anchored to a deploy. Use an absolute
rangewith the deploy’s time. - Lookup tables, such as a customer’s tier.
Errors
Value at the greatest ordering field
max_by(value, ordering_field) returns a numeric value from the row with the
greatest numeric ordering field or timestamp in each group and window. For example,
max_by(duration, timestamp) returns the latest span’s duration, while
max_by(severity_number, struct.observations.process_sequence) follows report sequence.
Equal ordering values select the higher result. Missing or invalid numeric inputs
are skipped; no matching valid rows means no data. This reads raw records and uses
the existing query limits. Text results and forecasting over max_by are not supported.
Use condition_guide topics observation_health and observation_health_reports
for an Observation-health monitor and an inspection query. Health reports describe
configured Observations; they do not prove application telemetry is arriving.