loki.process component sits between the source and the writer and runs each log line through an ordered series of stages before storage. A typical pipeline for the example above:
matchstage: select only logs from the application we care about.jsonstage: parse log lines and extract fields such asmethodandcode.labelsstage: convert selected extracted fields into indexed labels for fast querying.
Always run extraction stages (for example
json) before labels. If you label first, there is nothing to extract from the newly indexed fields.Keep labels low-cardinality. Use labels for fields with a small, bounded set of possible values (for example, HTTP status codes or
environment). For high-cardinality values (for example, request IDs or user IDs), keep them as structured metadata so you can filter them after the selector with pipes instead of promoting them to labels.
For values that should not be indexed, use structured metadata. Structured metadata is attached to each log line but not indexed; you can still filter or query these fields after the selector with a pipe without the costs of making them labels.
Further reading and references:
