Reference

Observability & troubleshooting

Read logs, metrics and traces; query service behavior and reason about alerts and missing evidence.

Scope and conventions

PromQL uses classic counter/gauge/histogram series; Loki examples use LogQL log pipelines. Metric names and log fields are an explicit example schema, not automatic SDK output. Queries need data with that schema. Native language logging and HTTP recipes remain in Programming languages.

Metrics & PromQL

Select an instant or range vector

Telemetry & queries

A bare selector returns recent samples per matching series at an evaluation time. A range selector supplies samples over an interval to a range function. A plotted range query repeats evaluation over time.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Select an instant or range vector
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
api_requests_total{job="api"}
api_requests_total{job="api"}[5m]

Apply rate before aggregating counters

Telemetry & queries

rate estimates per-second counter increase over a window and accounts for resets. Calculate it per original series before aggregation so resets are still visible to the function.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Apply rate before aggregating counters
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sum by (route) (rate(api_requests_total{job="api"}[5m]))

Interpret increase as an extrapolated window total

Telemetry & queries

increase accounts for counter resets and extrapolates to the selected window. The result can be fractional; it is not an exact event ledger or a substitute for an audit record.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Interpret increase as an extrapolated window total
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sum(increase(api_requests_total{job="api"}[1h]))

Use the same population in a numerator and denominator

Telemetry & queries

Divide the error rate by the total request rate for the same scope/window. A zero denominator or absent series requires a deliberate no-traffic/no-data policy; do not automatically interpret it as a healthy zero.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Use the same population in a numerator and denominator
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sum(rate(api_requests_total{job="api",status=~"5.."}[5m]))
/
sum(rate(api_requests_total{job="api"}[5m]))

Compute mean duration from histogram sum and count

Telemetry & queries

For a seconds-valued histogram, divide the rate of the sum by the rate of the count to get a request-weighted mean in seconds. A mean does not describe the tail.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Compute mean duration from histogram sum and count
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sum(rate(api_request_duration_seconds_sum{job="api"}[5m]))
/
sum(rate(api_request_duration_seconds_count{job="api"}[5m]))

Aggregate classic histogram buckets before estimating p95

Telemetry & queries

Keep the le bucket boundary label when summing classic histogram bucket rates. histogram_quantile interpolates within buckets; accuracy depends on their layout. The +Inf bucket must exist.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Aggregate classic histogram buckets before estimating p95
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
histogram_quantile(0.95,
  sum by (le) (rate(api_request_duration_seconds_bucket{job="api"}[5m]))
)

Do not average per-instance percentiles

Telemetry & queries

Client-calculated summary quantiles generally cannot be aggregated into a fleet quantile. Use an appropriate histogram for aggregate quantile estimates, or inspect each summary quantile within its own population.

Protocol / decision sketch

Sequence or decision sketch; not executable code.

Telemetry & queries · Do not average per-instance percentiles
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
p95(instance A) + p95(instance B)
--------------------------------  is not fleet p95
                2

Distinguish absent telemetry from an observed zero

Telemetry & queries

An absent series is different from an existing zero-valued sample. absent_over_time can detect no samples for a selector; decide separately whether that means missing instrumentation, scrape failure or no applicable target.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Distinguish absent telemetry from an observed zero
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
absent_over_time(up{job="api"}[10m])

up=0 describes a failed scrape for an existing target; no up series may indicate discovery/configuration absence.

Match labels deliberately when combining vectors

Telemetry & queries

Vector arithmetic matches series by labels unless a matching modifier changes that rule. Unmatched series can disappear. Check populations and cardinality before using on/ignoring or group_left/group_right.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Match labels deliberately when combining vectors
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sum by (job) (rate(api_requests_total{status=~"5.."}[5m]))
/ on (job)
sum by (job) (rate(api_requests_total[5m]))

Measure queue pressure and saturation in their units

Telemetry & queries

An instantaneous gauge can show current backlog or in-flight work; a range aggregation can show recent maxima. Interpret pressure alongside service rate, capacity and user impact rather than treating one sample as a diagnosis.

Query expression

PromQL expression. Metric names/labels below belong to the illustrative API instrumentation, not built-in Prometheus HTTP metrics.

Telemetry & queries · Measure queue pressure and saturation in their units
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
max_over_time(api_inflight_requests{job="api"}[5m])