---
title: RailQL cookbook
description: Copy RailQL queries for memory, traffic, latency, logs, DNS, and volumes, or follow a troubleshooting workflow.
---
These queries answer common observability questions. Replace service and volume names with your own, and choose the time range in the explorer. A `--` comment runs to the end of the line and can be pasted with the query.

<Banner variant="primary">RailQL is available through <a href="/platform/priority-boarding">Priority Boarding</a>. Breaking changes may occur.</Banner>

## Memory and replicas

Measure each replica's utilization before comparing replicas. Dividing the sum of all replicas' memory by one replica's limit can exceed 100% even when each replica is below its limit.

```railql
-- Memory utilization per replica
((metric railway.memory.usage) /
 (metric railway.memory.limit)) | to %
```

```railql
-- Highest per-replica utilization, per service
((metric railway.memory.usage) /
 (metric railway.memory.limit)) | to % | max by service
```

If three replicas each use 512 MiB with a 1 GiB limit, each is at 50%. The second query reports 50% for the service, not 150%. It reports the highest replica utilization, not combined capacity utilization.

```railql
-- Peak recorded memory per replica
metric railway.memory.usage{service=api} rollup max
```

Keep the replica labels to identify which replica spiked. Peaks between recorded samples may be missed, so this query can't prove the memory level at the instant of an out-of-memory kill.

```railql
-- Memory of the old and new deployments during a deploy
metric railway.memory.usage{service=api} | sum by deployment
```

```railql
-- Replicas reporting CPU data in each step
metric railway.cpu.time{service=api} | count_series
```

## Traffic and latency

Count requests to measure traffic. Use distributions to calculate percentiles across requests.

```railql
-- Public egress per service, in bytes per second
metric railway.network.tx | sum by service | rate
```

```railql
-- Requests per second by status class
http{service=api} rollup count by http_status_class | rate
```

```railql
-- Requests that took more than two seconds
http{service=api total_duration>2s}
```

```railql
-- p99 HTTP latency per path
http{service=api} rollup histogram(total_duration) by path | p99
```

```railql
-- p99 server span duration per operation
spans{service=api kind=server} rollup histogram(duration) by name | p99
```

The last two queries show latency over time for each group. They don't sort or rank the groups. Paths with unique IDs can exceed the series limit; instrumented spans with a normalized `@http.route` attribute can provide a more useful grouping.

```railql
-- Total time spent in client spans, per service
spans{kind=client} rollup sum(duration) by service
```

Client spans can overlap, so their total duration isn't elapsed wall-clock time.

## Application errors

Structured log keys let you count errors by application-specific values without adding a separate metric.

```railql
-- Error log lines per second, per service
logs{level=error} rollup count by service | rate
```

```railql
-- Unique users with error logs in each step
logs{level=error} rollup count_distinct(@user_id)
```

```railql
-- Error log rate by application error code
logs{level=error @error.code=*} rollup count by @error.code | rate
```

The last two examples require your application to emit the corresponding structured keys. Distinct counts are per step; use the Number visualization for distinct users over the whole range.

## Traces

The `traces` source has one row per trace, built from the trace's spans. Its filter matches a trace when any of its spans matches.

```railql
-- Failed traces of a service
traces{service=api status=error}
```

```railql
-- p99 trace duration
traces{service=api} rollup histogram(duration) | p99
```

```railql
-- Traces per second by root service
traces rollup count by root_service | rate
```

## DNS and storage

DNS events help investigate name resolution. Volume metrics track storage consumption.

```railql
-- Failed DNS lookups by queried name
dns{status=failed} rollup count by qname
```

```railql
-- Percentage of each volume instance in use
((metric railway.volume.usage{volume=data}) /
 (metric railway.volume.size{volume=data})) | to %
```

## Investigate an increase in errors

Start with a chart to locate the problem, then inspect the events behind it. Keep the same environment and narrow the time range as you go.

### Locate the spike

Chart failed requests per second and zoom into the affected interval:

```railql
http{service=api http_status>=500} rollup count | rate
```

### Identify the affected paths

Split the count by path to see where the failures occur:

```railql
http{service=api http_status>=500} rollup count by path | rate
```

### Inspect individual requests

Remove the rollup and filter to an affected path. This example uses `/checkout`:

```railql
http{service=api http_status>=500 path=/checkout}
```

Click a row to inspect its duration, request ID, and response details.

### Check application logs and traces

Read error logs from the same service and time range:

```railql
logs{service=api level=error}
```

If your logs include a trace ID, use it to open the corresponding trace. Replace this example ID with the one from your log:

```railql
spans{trace_id=4bf92f3577b34da6a3ce929d0e0e4736}
```

The explorer displays a waterfall when a span query selects one trace. Use it to inspect the spans around the failing operation. See [Tracing](/observability/tracing) to instrument your service.