CQL cheat sheet

Common tasks as copyable CQL, with the closest construct in LogQL, Splunk SPL and CloudWatch Logs Insights.

On this page

The time range is never in the query. Set it with the time picker. Full grammar: CQL reference.

Filter by level

Filter
cql
level=error
In LogQL / SPL / CloudWatch Insights
  • LogQL: {app="x"} | level="error"
  • SPL: level=error
  • CloudWatch: filter level = "error"

Substring or regex

Search
cql
msg ~ "time.*out"
In LogQL / SPL / CloudWatch Insights
  • LogQL: |~ "time.*out"
  • SPL: | regex _raw="time.*out"
  • CloudWatch: filter @message like /time.*out/

Free text, case-exact phrase

Search
cql
c"OOMKilled"

Plain words and quoted phrases ignore case. The c prefix matches case exactly.

Several values, exclude a host

Filter
cql
service=pay-api level IN (error,fatal) NOT host=app2

Count by field

Stats
cql
stats count() by service
In LogQL / SPL / CloudWatch Insights
  • LogQL: sum by (service) (count_over_time(...))
  • SPL: stats count by service
  • CloudWatch: stats count(*) by service

95th percentile

Stats
cql
stats p95(duration_ms)
In LogQL / SPL / CloudWatch Insights
  • LogQL: quantile_over_time(0.95, ...)
  • SPL: stats p95(duration_ms)
  • CloudWatch: stats pct(duration_ms, 95)

Distinct count

Stats
cql
stats dc(user_tok)
In LogQL / SPL / CloudWatch Insights
  • LogQL: n/a
  • SPL: stats dc(user_tok)
  • CloudWatch: stats count_distinct(user_tok)

Time buckets

Time
cql
timechart span=5m count()
In LogQL / SPL / CloudWatch Insights
  • LogQL: count_over_time(...[5m])
  • SPL: timechart span=5m count
  • CloudWatch: stats count(*) by bin(5m)

Top N

Top and rare
cql
top 5 service
In LogQL / SPL / CloudWatch Insights
  • LogQL: topk(5, ...)
  • SPL: top limit=5 service
  • CloudWatch: stats count(*) by service | sort ... | limit 5

Rare N

Top and rare
cql
rare 5 service
In LogQL / SPL / CloudWatch Insights
  • LogQL: bottomk(5, ...)
  • SPL: rare limit=5 service
  • CloudWatch: no direct form

Sort descending

Shape
cql
stats count() by service | sort -count
In LogQL / SPL / CloudWatch Insights
  • LogQL: n/a
  • SPL: sort - count
  • CloudWatch: sort count desc

Limit rows

Shape
cql
limit 50
In LogQL / SPL / CloudWatch Insights
  • LogQL: n/a
  • SPL: head 50
  • CloudWatch: limit 50

Choose fields

Shape
cql
fields ts, msg
In LogQL / SPL / CloudWatch Insights
  • LogQL: n/a
  • SPL: table ts, msg
  • CloudWatch: fields @timestamp, @message

Find delivery gaps

Search
cql
source=gaps

Gaps found by the reconciler. source= must be the first term.

Not in CQL#

OpenTelemetry field aliases#

Both names work in queries and saved queries (source=events): severity_text→level, http.response.status_code / http.status_code→http_status, url.path→http_path, service.name→service, host.name→host, enduser.id→user_tok. trace_id, span_id, severity_number are attribute fields. See Ingest overview.

Report an inaccuracy (opens a support ticket in the portal; nothing is sent from this page)