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.

Logs & LogQL

Emit one structured event with useful context

Telemetry & queries

Use a stable event schema and an unambiguous timestamp. Include enough service, operation and correlation context to join an event to a request; keep credentials and sensitive payloads out of telemetry.

Fragment

Application-defined JSON log line; an ingestion pipeline must attach the intended Loki stream labels.

Telemetry & queries · Emit one structured event with useful context
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
{"timestamp":"2026-10-31T12:00:00Z","service_name":"api","event":"request_finished","request_id":"req-42","status":503,"duration_seconds":0.25}

Select streams before parsing their contents

Telemetry & queries

A Loki stream selector matches indexed labels. Start with relevant service/environment labels and a bounded time range; parsed JSON fields are not automatically indexed stream labels.

Query expression

LogQL expression for Loki. service_name is an indexed stream label; JSON fields must exist in the log line. Select the investigation time range in your client.

Telemetry & queries · Select streams before parsing their contents
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
{service_name="api", environment="staging"}

Filter literal log text before expensive parsing

Telemetry & queries

|= retains lines containing a case-sensitive literal string; != excludes lines containing one. These are line filters, not JSON field comparisons.

Query expression

LogQL expression for Loki. service_name is an indexed stream label; JSON fields must exist in the log line. Select the investigation time range in your client.

Telemetry & queries · Filter literal log text before expensive parsing
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
{service_name="api"} |= "request_finished" != "healthcheck"

Parse JSON and check extraction errors

Telemetry & queries

The json stage extracts fields for later pipeline filters. Invalid JSON or numeric conversions can set __error__; filter those errors after the stages that may fail.

Query expression

LogQL expression for Loki. service_name is an indexed stream label; JSON fields must exist in the log line. Select the investigation time range in your client.

Telemetry & queries · Parse JSON and check extraction errors
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
{service_name="api"}
  | json
  | status >= 500
  | __error__=""

Count matching log events per second

Telemetry & queries

rate over a log range measures matching entries per second. It is only a request-error rate if the logging and ingestion policy actually records one matching event per failed request.

Query expression

LogQL expression for Loki. service_name is an indexed stream label; JSON fields must exist in the log line. Select the investigation time range in your client.

Telemetry & queries · Count matching log events per second
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sum(rate({service_name="api"} |= "request_failed" [5m]))

Calculate a quantile from numeric log fields

Telemetry & queries

unwrap converts a field into samples for range aggregation. Filter conversion errors after unwrap; by(service_name) combines the example’s eligible samples per service. This distribution covers retained/logged events, which may differ from all requests.

Query expression

LogQL expression for Loki. service_name is an indexed stream label; JSON fields must exist in the log line. Select the investigation time range in your client.

Telemetry & queries · Calculate a quantile from numeric log fields
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
quantile_over_time(0.95,
  {service_name="api"}
    | json
    | unwrap duration_seconds
    | __error__="" [5m]
) by (service_name)