SpitfireLoad Testing & APMWhat's new

SFQL reference

SFQL is Spitfire's read-only query language for dashboard panels. A query picks rows from a dataset, filters, groups and sorts them. For how panels are built, see Dashboards. To try a query, open APM → Dashboards → SFQL editor.

The shape of a query

sql
SELECT bucket(ts) AS t, service, sum(count) AS requests
FROM requests
WHERE service = $service AND http_status >= 500
GROUP BY t, service
HAVING sum(count) > 0
ORDER BY t
LIMIT 1000
  • SELECT and FROM are required; WHERE, GROUP BY, HAVING, ORDER BY and LIMIT are optional.
  • The time range and the picked environment are added to the query for you; there is no need to write the time in WHERE.
  • LIMIT is at most 10000. Without it, 10000 is used.
  • Keywords can be upper or lower case. Text goes in single quotes: 'GET /orders'.
  • There is no JOIN, UNION, subquery or command that changes data.

Datasets

Dataset What it holds
spans Every span: duration, error, service, endpoint, database, queue, LLM and Kubernetes details
requests Per-minute request rollup: requests, errors, duration and p50/p95/p99. The fastest over long ranges
requests_by_host Per-minute request rollup, broken down by host
requests_k8s Per-minute request rollup, broken down by Kubernetes and container
dependencies Calls from services to databases, queues and outside addresses
db_queries Database queries, by masked query pattern
external_calls Outgoing HTTP calls
messaging Queue and topic traffic
llm LLM calls: provider, model, tokens, errors
slo SLO measurements
logs Log records: level, message, pattern, service
metrics Metrics sent by applications (runtime and custom metrics)
errors Errors and exceptions
hosts Hosts that send data and their services
host_calls Calls between hosts
rum Real user monitoring: page loads, requests, country, browser
web_vitals Web Vitals of the pages
business Business metrics defined in Settings → Business metrics
runs Load-test runs, one row per run: status, result, requests, throughput, p50/p95/p99, error rate, VUs
run_steps Each step of each run: requests, errors, error rate, latency percentiles
run_metrics Every metric's whole-run summary per run, also per step, check and location
run_points The runs' per-second points: VUs, requests, latency over time
run_thresholds The runs' thresholds (SLA): the observed value and pass/fail
anomalies Learned anomalies: service, metric, direction, severity, open or resolved

Every dataset's columns, types and descriptions are in the list on the right of the SFQL editor. On spans, logs and the other datasets that carry attributes, attr('http.route') reads a span or log attribute and res('k8s.namespace.name') a resource attribute.

Load tests and anomalies

The runs, run_steps, run_metrics, run_points and run_thresholds datasets read your load tests; you need access to Runs to see them, and a user limited to groups sees only the tests of their groups. A run falls into the time range by when it was started (ts). anomalies reads the anomalies APM learned, by when they started; you need access to APM. On run_metrics and run_points, total keeps the whole run's numbers (no step, check or location); the metric is picked with metric: reqs (requests), req_duration (response time, ms), req_failed (failed requests), vus (virtual users), checks.

Per-minute rollups

On rollup datasets such as requests, dependencies and llm, each row sums up one minute. Add up the number columns with sum: sum(count), sum(errors). The average duration is sum(dur_ms_sum) / sum(count). Percentiles come only from p50(), p95() and p99(); quantile does not work on these datasets.

Variables

Variable Replaced by
$service The service picked at the top of the page
$env The picked environment
$name The dashboard's variable called name

An empty variable drops the comparison it is in: with no service picked, service = $service returns every service.

Operators

Operator Example
=, !=, <, <=, >, >= http_status >= 500
AND, OR, NOT is_error AND NOT service = 'auth'
IN, NOT IN level IN ('error', 'fatal') (at most 200 values)
BETWEEN duration_ms BETWEEN 100 AND 500
LIKE, ILIKE endpoint LIKE 'GET /api/%' (ILIKE ignores case)
IS NULL, IS NOT NULL peer_service IS NOT NULL
+, -, *, / 100 * sum(errors) / sum(count)

Functions

Function What it does
count(), count_if(condition) Row count; count of the rows that match
sum, avg, min, max Sum, average, smallest, largest
sum_if(x, condition), avg_if(x, condition) Sum and average of the rows that match
uniq(x), count_distinct(x) Number of different values
any(x) One value from the group
p50(x), p95(x), p99(x) Percentile; on rollups the brackets stay empty
quantile(0.9, x), percentile(90, x) The percentile you ask for
bucket(ts), bucket(ts, '5m') Cuts time into slices; without a width, it is picked from the time range
if(condition, a, b) a when the condition holds, b otherwise
round(x, n), abs, floor, ceil Rounding and absolute value
greatest, least The largest and smallest of the values
lower, upper, trim, length Text functions
concat, substring, to_string, to_number Joining, cutting and converting values
now() The current time

Write the bucket() width like '30s', '5m', '1h', '1d'. A time range is cut into at most 2000 slices; on rollups the finest slice is 1 minute.

Picking a chart

The editor looks at the result's columns and opens the charts that suit it:

Result Charts that suit it
A time column and numbers (with bucket(ts)) Line, area, bars, table
A text column and numbers Bars, horizontal bars, pie (with one number column), table
One row of numbers Number, gauge (with one number), table
Anything else Table

When a text column sits next to the time column (for example service), each value becomes its own line; at most 20 lines are drawn.

Examples

Error rate per service:

sql
SELECT service, round(100 * sum(errors) / sum(count), 2) AS error_rate
FROM requests
GROUP BY service
ORDER BY error_rate DESC
LIMIT 10

Slowest database queries:

sql
SELECT db_query, count() AS calls, round(p95(duration_ms), 1) AS p95_ms
FROM spans
WHERE db_system IS NOT NULL AND service = $service
GROUP BY db_query
ORDER BY p95_ms DESC
LIMIT 20

Logs by level:

sql
SELECT bucket(ts) AS t, level, count() AS logs
FROM logs
WHERE level IN ('error', 'warn')
GROUP BY t, level
ORDER BY t

p95 and error rate of the latest runs of a test (add a test variable to the dashboard):

sql
SELECT ts, run, round(p95_ms, 1) AS p95_ms, round(error_rate, 2) AS error_rate
FROM runs
WHERE test = $test AND requests > 0
ORDER BY ts DESC
LIMIT 20

Requests per second and VUs during the runs:

sql
SELECT bucket(ts) AS t, round(avg_if(count, metric = 'reqs'), 1) AS rps, round(avg_if(value, metric = 'vus'), 1) AS vus
FROM run_points
WHERE total AND metric IN ('reqs', 'vus')
GROUP BY t
ORDER BY t

Open anomalies per service:

sql
SELECT service, count() AS anomalies, count_if(severity = 'critical') AS critical
FROM anomalies
WHERE open
GROUP BY service
ORDER BY anomalies DESC
Tip

Over long ranges (7 days, 30 days), use a rollup dataset such as requests instead of spans; the panel opens much faster.

Error messages

When a query does not run, the editor shows the error with its line and column under the query and marks the place. Common ones:

Message What to do
The dataset has no such column Insert the column name from the list on the right; each dataset has its own columns
The column is not in GROUP BY Put every column in SELECT that is not aggregated into GROUP BY too, or aggregate it with a function such as count or sum
This width cuts the time range into more than 2000 buckets Write a wider slice such as bucket(ts, '1h') or leave the width empty