/platform-extras-skills:logql-query-authoringfrom platform-extras-skills
Writes and debugs LogQL queries against Grafana Loki — stream selectors, line filters, parsers, label filters, and metric queries (rate, count_over_time). Use for writing new queries, extracting fields, or fixing slow/timeout queries.
Ships in platform-extras-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
LogQL is Loki's query language, deliberately modeled on PromQL but operating over log lines instead of numeric samples: a query starts with a stream selector (label matchers, cheap — Loki uses these to find which chunks to read at all) and then applies a pipeline of line filters and parser/label-filter stages that get progressively more expensive because they have to actually read and process log content. Writing an effective LogQL query is mostly about ordering that pipeline correctly and knowing when a query has stopped being "narrow by label" and started being "scan everything and grep," which is the single biggest cause of slow or timed-out Loki queries. This skill covers stream selectors, line filters, structured parsing, and LogQL's metric queries; it assumes Loki itself is already ingesting logs — see loki-log-aggregation-configuration for ingestion, retention, and storage backend configuration, which this skill does not repeat.
app, namespace, env) — see
loki-log-aggregation-configuration
and
loki-configuration-validation
if labels are unbounded/high-cardinality, since that's a labeling/
ingestion problem, not something a query can work around.{app="payments-api"} |= "" with no further pipeline, limited to a short time range) before
writing a parser expression against an assumed format.| pattern) syntax; earlier
versions support | json, | logfmt, | regexp but not | pattern.Start every query with the narrowest possible stream selector — this is the cheap part that determines which chunks Loki even has to read; everything after it is line-by-line processing cost:
{app="payments-api", namespace="payments", env="production"}
A selector with only one broad label ({app="payments-api"} across
all namespaces/environments) forces Loki to scan far more data than
a fully-scoped one — always add every label you know, not just enough
to be "roughly right."
Filter on line content before parsing structure, using |=
(contains), != (does not contain), |~ (regex match), !~ (regex
non-match) — plain substring filters (|=/!=) are cheaper than
regex and should come first in the pipeline:
{app="payments-api", env="production"} |= "error" != "healthcheck"
{app="payments-api", env="production"} |~ `timeout|connection refused`
Order matters: put the filter that eliminates the most lines first,
and prefer |=/!= substring filters over |~/!~ regex whenever
a plain substring is sufficient — regex evaluation is meaningfully
more expensive per line at high volume.
Parse structured fields only after filtering down to the lines you actually need — parsing every line in a broad selector before filtering wastes CPU on lines you'll discard anyway:
# JSON logs
{app="payments-api", env="production"} |= "error"
| json
| status_code >= 500
# logfmt logs (key=value pairs)
{app="payments-api", env="production"} |= "error"
| logfmt
| duration > 2s
# semi-structured plain text via pattern parser
{app="payments-api", env="production"}
| pattern `<ip> - - [<timestamp>] "<method> <path> <_>" <status> <size>`
| status >= 500
| json and | logfmt auto-extract all top-level keys as labels
available to subsequent filter stages; | pattern and | regexp
require an explicit capture template/expression when the format isn't
already structured.
Filter on extracted fields with the same comparison operators as
PromQL (==, !=, >, <, >=, <= for numbers; =, !=,
=~, !~ for strings), applied as a label filter stage after
parsing:
{app="payments-api"} | json | status_code >= 500 and method = "POST"
Warning: fields extracted via
| json/| logfmtbecome labels for the query pipeline only — they are not written back as indexed stream labels. Don't confuse a parsed-field filter (cheap only relative to scanning raw text, still requires reading every line in the narrowed stream) with an actual indexed label selector (near-free). If you filter on the same extracted field constantly, consider whether it should be promoted to a real ingestion-time label instead — see loki-log-aggregation-configuration.
Turn a log stream into a metric query for dashboards/alerts using LogQL's PromQL-like aggregation functions:
# count of matching lines per second, per service, over 5m windows
sum by (app) (
count_over_time({app="payments-api", env="production"} |= "error" [5m])
)
# rate() variant — per-second rate rather than raw count
sum by (app) (
rate({app="payments-api", env="production"} |= "error" [5m])
)
# extracted numeric field aggregated as a metric (e.g. request duration)
quantile_over_time(0.99,
{app="payments-api"} | json | unwrap duration_ms [5m]
) by (app)
count_over_time/rate operate on line counts; unwrap promotes a
parsed numeric field into the value stream so range-vector functions
like quantile_over_time/avg_over_time/sum_over_time can operate
on the field's actual value instead of just counting matching lines.
Use label_format/line_format to reshape output for readability
or to prep labels for aggregation, sparingly — these run per-line
like parsing, so apply them after filtering, not before:
{app="payments-api"} | json
| line_format `{{.timestamp}} {{.status_code}} {{.path}} ({{.duration_ms}}ms)`
Set an explicit, bounded time range on every query — Loki (correctly) refuses or heavily throttles unbounded/very-wide range queries against high-volume streams:
logcli query '{app="payments-api"} |= "error"' --from="2026-07-28T00:00:00Z" --to="2026-07-28T06:00:00Z" --limit=1000
Warning — unbounded query risk: a broad stream selector (or no selector narrowing at all) combined with a wide time range and a regex line filter is exactly the query shape that can overwhelm a Loki cluster — it forces scanning and regex-matching against every line across many chunks/ingesters simultaneously. Always scope by label first, keep the time range as narrow as the investigation allows, and add
--limit/a dashboard panel row limit so a runaway query doesn't return (or attempt to return) millions of lines.
|=/!=) → regex line filter (|~/!~) if needed → parser
(json/logfmt/pattern) → label filter on extracted fields.|=/!= over |~/!~ whenever a plain substring suffices —
reserve regex filters for genuinely variable patterns.--limit/
dashboard row limit, especially for ad hoc investigation queries run
directly against production.| pattern, | regexp) against a
handful of real sample lines in Explore before trusting it across a
wide time range — a subtly wrong capture pattern silently drops or
mis-extracts fields rather than erroring.Symptom: A LogQL query that looks reasonable times out or returns a "query too large"/"maximum series/entries" error from Loki. Fix: The stream selector is too broad relative to the time range (or has no narrowing labels at all), forcing a scan across far more chunks than intended. Add every known label to the selector, narrow the time range, and only widen deliberately once the query is proven correct on a small slice.
Symptom: A | json parser stage silently produces no error but
none of the expected fields are available for filtering downstream.
Fix: The log lines aren't actually JSON on every line matched by
the selector/line filter (e.g. a mix of structured and plain-text
lines, or a JSON line wrapped in extra prefix text from the container
runtime). Inspect a handful of raw lines first
({app="x"} |= "" with no parser, small time range) to confirm the
actual format before adding | json.
Symptom: A regex line filter (|~) that works fine in isolated
testing becomes dramatically slower once applied across a full
production time range.
Fix: Regex filters are meaningfully more expensive per line than
substring filters at volume. Replace with a |=/!= substring filter
if the pattern can be expressed as one, and if regex is unavoidable,
narrow the stream selector and time range further to reduce the number
of lines the regex has to run against.
Symptom: A metric query (count_over_time/rate) used in a
dashboard/alert returns wildly different numbers than manually counting
matching lines in Explore for the same window.
Fix: Check the range-vector duration ([5m]) matches the
evaluation/scrape interval assumptions the same way PromQL's rate()
does — too short a window relative to how the panel refreshes produces
misleading extrapolation, and a query re-run with a different --to/
--from than expected (e.g. relative vs. absolute time in a saved
dashboard) silently changes the window being counted.
Symptom: An ad hoc investigation query run directly against
production during an active incident makes Loki itself slow to respond
for everyone, compounding the incident.
Fix: This is exactly the unbounded-query risk — an under-scoped
selector with a wide time range and a regex filter run under
incident-time pressure. Scope by every known label, keep the range as
narrow as the investigation allows (extend only if the narrow window
comes back empty), and add --limit — treat "just grep everything"
as a red flag during a live incident, not a shortcut.
Symptom: Filtering on a field extracted via | logfmt/| json
(e.g. user_id) works but is consistently slow no matter how the query
is restructured.
Fix: A parsed-field filter still requires reading and parsing every
line in the narrowed stream — it is not as cheap as an indexed label
selector. If this field is queried constantly, it likely belongs as a
real ingestion-time label instead (with its cardinality reviewed first
— see
loki-log-aggregation-configuration),
not repeatedly re-parsed per query.
Scenario: During an incident, payments-api is returning elevated
5xx errors. Logs are JSON with status_code, duration_ms, and
request_id fields, labeled by app/namespace/env at ingestion.
{app="payments-api", namespace="payments", env="production"} |= ""
{app="payments-api", namespace="payments", env="production"}
|= "status_code"
| json
| status_code >= 500
sum by (app) (
rate(
{app="payments-api", namespace="payments", env="production"}
| json
| status_code >= 500 [5m]
)
)
quantile_over_time(0.99,
{app="payments-api", namespace="payments", env="production"}
| json
| status_code >= 500
| unwrap duration_ms [5m]
) by (app)
request_id from a failing line and pivot to the trace
backend using that ID, correlating the log-level finding with a
specific distributed trace — see
incident-investigation-using-metrics-logs-traces
for the full cross-signal workflow this feeds into.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
16 skills in this plugin
/backstage-developer-portalGuides building an internal developer portal with Backstage — authoring catalog-info.yaml to register services in the software catalog, setting up TechDocs for docs-as-code, writing Software Templates to scaffold new services, and understanding the plugin architecture. Use when a user asks to "register a service in Backstage", "write a catalog- info.yaml", "set up TechDocs", "create a Backstage software template for scaffolding new repos", "add a Backstage plugin", or "build an internal developer portal."
/distributed-tracing-with-tempo-and-jaegerGuides configuring Grafana Tempo or Jaeger as the distributed tracing backend — trace storage backend selection and retention, sampling strategy at the backend/collector level (head-based vs. tail-based), and trace-to-metrics/trace-to-logs correlation so a trace ID can pivot directly into a log line or a metrics exemplar. Use when the user asks to "set up Tempo," "configure Jaeger storage," "set trace retention," "configure trace-to-logs correlation in Grafana," "design a sampling strategy for traces," or "query traces with TraceQL." This is the tracing *backend/storage* layer — instrumenting applications and configuring the OpenTelemetry Collector that feeds this backend is covered separately in opentelemetry-instrumentation-and-collector-configuration.
npx claudepluginhub selvarajmurugesan90/ops-engineering-skills --plugin platform-extras-skillsOther plugins' skills for the same job