Skip to content

OQL Reference

OQL is a pipeline language. Every query starts with a source and then applies zero or more stages.

source | stage | stage
SourceData
spansIndividual spans.
tracesTrace summaries from trace_index.
logsLog records.
metricsMetric points and rollups.
StageExample
wherewhere service == "api" and duration > 250ms
statsstats p95(duration), count() by http.route, bin(1m)
toptop 10 by p95
sortsort duration desc
limitlimit 100
fieldsfields time, service, body

Stage order is constrained. Filtering and projection happen before aggregation; top, sort, and limit shape results after aggregation or listing.

FormExample
Comparisonduration > 250ms
Equalityservice == "api"
Inequalitystatus_code != "ok"
Regex`body =~ “timeout
Negative regexbody !~ "debug"
In listhttp.status in (502, 503, 504)
Not in listhttp.method not in ("GET", "HEAD")
Existspeer.service exists
Containsbody contains "timeout"
Starts withurl.path startswith "/v1/"
Boolean logica == 1 and (b == 2 or c == 3)
LiteralExample
String"api"
Number42, 3.14
Booleantrue, false
Duration250ms, 1s, 5m, 2h, 1d
Bytes4MiB, 1536KiB
Severitytrace, debug, info, warn, error, fatal

Backtick-quote reserved words or unusual field parts:

spans | where `limit` == 1

The accepted aggregation function set is closed:

FunctionArgumentsNotes
count()noneCount rows.
count_if(predicate)predicateCount rows matching a predicate.
count_distinct(field)any fieldApproximate distinct count.
sum(field)numeric fieldSum.
avg(field)numeric fieldAverage.
min(field)numeric fieldMinimum.
max(field)numeric fieldMaximum.
stddev(field)numeric fieldSample standard deviation.
p50(field)numeric fieldTDigest quantile, histogram path for eligible metrics.
p75(field)numeric fieldTDigest quantile on raw data.
p90(field)numeric fieldTDigest quantile, histogram path for eligible metrics.
p95(field)numeric fieldTDigest quantile, histogram path for eligible metrics.
p99(field)numeric fieldTDigest quantile, histogram path for eligible metrics.
rate() or rate(field)optional numeric fieldMetrics-only, sole aggregation.
latest(field)any fieldValue with latest timestamp.
heatmap(field)numeric fieldSole aggregation. Only bin() grouping is allowed.

Use fields and optionally one time bin:

spans | stats count() by service, bin(1m)

bin(auto) picks a bucket width from a fixed ladder and keeps the bucket count under the query limit. Explicit bins below 1s are rejected.

Common fields:

SourceFields
spanstime, duration, trace_id, span_id, parent_span_id, name, kind, status_code, status_message, service, scope_name, scope_version
tracestime, duration, span_count, error_count, root_service, root_name, trace_id, service
logstime, observed_time, severity, severity_number, severity_text, body, body_kind, event_name, trace_id, span_id, service, scope_name, scope_version
metricstime, start_time, name, unit, value, service, point_kind, temporality, is_monotonic, scope_name, scope_version

Promoted span attributes:

http.request.method
http.method
http.route
http.response.status_code
http.status_code
http.status
url.path
rpc.system
rpc.method
db.system.name
db.system
db.operation.name
db.operation
messaging.system
peer.service
exception.type
exception_type

Resource attributes use the resource. or res. prefix:

spans | where resource.k8s.namespace.name == "prod"
logs | where res.host.name == "node-a"

Unknown fields on spans, logs, and metrics resolve to telemetry attribute maps when the source supports attribute maps. Unknown fields on traces are rejected.

LimitValue
Maximum parenthesis depth64
Maximum in list values4096
Maximum explicit limit1000000
Query execution timeout15s
Aggregate scan budget4000000000 rows
List scan budget1000000000 rows
Default row limit10000
Top series limit50
Auto-bin bucket targetup to 240 buckets