Loki label best practices

Loki labels decide how streams are indexed, so choosing static, bounded labels keeps queries fast and storage affordable. This page explains which labels to use, which to avoid, and how to verify the result in your own cluster.

On this page

Loki label best practices start with stream count

Label only what identifies a stream, keep every label value bounded, and filter log content at query time instead of promoting it to a label. Teams running self-hosted Loki usually reach this review in one of two situations: before the first production ingest, when the labelling scheme is still cheap to change, or after slow queries, a growing index or many tiny chunks show that the scheme is already costing them. Either way, the starting point is the same. Loki indexes labels, not the text of log lines, so every unique combination of label values creates a separate stream. Each stream carries its own index entries and its own chunks in object storage, which means the label set you choose sets the size of the index before a single query runs.

Loki's own label guidance favours static labels such as region, cluster, server, application, namespace and environment, because these values change slowly and have a small, known set of possibilities. Warning signs of a poor choice include a label whose values grow with traffic, such as user IDs, request IDs, trace IDs or pod names that churn during deployments, and labels that multiply together, for example region times environment times pod. Illustrative case: if ten thousand short-lived pods each create a stream, Loki writes many small chunks where a few large ones would be cheaper to store and read. Before you ingest production data, write down the expected value count for each label, and ask your Loki vendor or integrator to confirm the label set your Grafana Alloy or OpenTelemetry pipeline will send by default, since some shippers add labels you did not choose.

Treat the label review as a recurring check, not a one-off design task. Run it again whenever you add a log source, change a shipper, or see query latency or index growth climb without a matching rise in log volume. Start by listing the labels on your busiest streams and comparing their value counts with what you intended. Values that should be content, such as an error message or a customer identifier, belong in the log line, where a line filter or a | json parser can reach them at query time. Where a field must stay queryable without being an index label, check the structured metadata and stream sharding topics in this group before you reach for more labels.

Which labels fit and which to avoid

This table compares common label categories against the dynamic values teams are tempted to index, showing when each label fits, what cardinality risk it carries and where the value should go instead. Read each row as a rule of thumb: keep labels static and bounded, and move per-request or per-entity values into structured metadata or line filters.

Label or valueWhen it fitsCardinality riskAlternative
Region, cluster, environmentFixed set of sites, clusters or stages that changes rarely, such as prod and stagingLow, as long as the list of values stays short and knownNot needed; keep as index labels
Namespace, application or serverOne value per deployed workload or host, with a small, stable inventoryModerate; grows with each new workload or host, so confirm the expected count with your teamKeep as labels when the set is bounded and the queries filter on them
Pod name or container IDRarely appropriate; pod names change on every rollout and restartHigh; each new pod creates new streams and small chunksStructured metadata, or a line filter when you only search for it
User ID, customer ID or session IDAlmost never as an index label, even for multi-tenant productsVery high; one stream per user multiplies the indexStructured metadata for lookup, or a line filter on the message text
Trace ID or request IDNot as a label; these identify one request, not a group of logsExtreme; nearly every line has a unique valueStructured metadata, then filter with a query over the field
Request path or URLOnly if you group by a small, normalized route template, such as /api/orders/:idHigh if raw paths are used, since IDs are embedded in themParse the path at query time, or use a line filter for specific strings
Log level or status codeSmall fixed set of values that you group or alert on frequentlyLow to moderate; the value set is bounded but can grow if raw codes are mixed inKeep as a label if bounded; otherwise parse from the line

Static and bounded labels that keep streams healthy

Loki indexes only labels, so every label you add multiplies the number of streams it must track. The label families below are the ones Loki's label best practices favour, and each one is worth checking against the number of values your environment really produces before it becomes an index key.

Region and cluster

Region and cluster identify where a log line was produced and change rarely. Each is a small, fixed set in most estates, so they make safe first labels. Before you commit, list every region and cluster that will ship logs into the same tenant, and confirm that clusters are not created per team, per branch or per build, because that quietly multiplies the stream count.

Label best practices

Namespace and environment

Namespace and environment usually map to Kubernetes namespaces or deployment tiers such as production, staging and test. They are bounded when teams follow a naming convention and the platform team controls who creates new namespaces. Check the live namespace count in each cluster, and flag any pattern that embeds a branch name, ticket number or developer name into the namespace.

Application and service

The application label groups logs by the software that produced them. It stays useful only while the catalog of applications is curated, so each value should correspond to a deployed service that a team owns. Ask who approves a new application name and whether short-lived jobs or preview deployments reuse one name or generate unique ones.

Server and host

Host labels suit fleets with stable machine names, such as a few hundred long-lived virtual machines. They become a problem when autoscaling groups or ephemeral build agents create new hostnames constantly. Measure how often hostnames change in your fleet, and if churn is high, keep the host identity in log content or structured metadata and label only the stable group that owns those hosts.

Testing value counts before rollout

The labels that look bounded on a diagram are not always bounded in production. Before you finalize the label set, count distinct values per label over a representative window in your own environment, using your current log shipper output or a sample of raw streams. Treat any label with a count that keeps climbing as a candidate for removal, and record the agreed ceiling so future label changes go through review.

Stable names over generated names

Labels should carry values that were chosen on purpose rather than values generated by a runtime. Generated identifiers such as container IDs, random suffixes or per-request values turn every new instance into a new stream. Agree a naming standard for each label family, document it with the people who ship logs, and confirm that your collection agents enforce it rather than passing through whatever the workload emits.

Filtering on content instead of labelling it

Some fields are used to narrow results to a known value and appear in most queries, such as a cluster, namespace or environment. These are the strongest candidates for a label because the set of values is small and stable, and Loki's guidance favours static labels such as regions, clusters, servers, applications, namespaces and environments. The test is whether the value set is bounded and whether every query will filter on it. If both are true, keep it as a label.

  • Bounded value set: Each new value multiplies the number of streams, so confirm that the total combinations stay modest across your environments.
  • Used in most queries: A label that is rarely filtered adds index cost without speeding up lookups.
  • Stable over time: Values that change with every deployment, such as build numbers, create new streams continuously.
  • Application-level keys: Application or service names usually qualify when each service runs in a known set of environments.
  • Illustrative example: A cluster label with three values and an environment label with four values give a small, predictable stream count.

Before you commit, count the possible combinations of your proposed labels and check that the result is small enough for your planned volume.

How to audit and set labels in your Loki pipeline

This sequence finds the labels that create excess streams in your current pipeline, removes or demotes them, and confirms that stream counts and queries behave correctly afterward.

  1. Inventory labels set in the shipper

    Someone on the platform or observability team reads the log shipper configuration, either Grafana Alloy or the OpenTelemetry Collector, and lists every place a label is attached: static labels in pipeline stages, labels copied from Kubernetes metadata, labels extracted from log content, and resource attributes promoted by the OTLP path. Record the file, the pipeline stage and the label name for each one. The step is done when every label that reaches Loki has an owner and a source line in a shared table. Confirm the exact configuration keys against the shipper version you run, because key names and default behavior change between releases.

  2. Count distinct values per label

    Using a sample window of representative traffic, count how many distinct values each label holds. Your Loki cluster exposes stream and label information through its query and metrics endpoints, and the Loki monitoring documentation describes how to check active streams per tenant. Compare the count for each label against what the label is meant to represent. A label such as cluster or environment should have a small, fixed set of values, while a label that carries a request ID, user ID or pod name will show a value count that grows with traffic. The step is done when each label has a recorded count and a bounded or unbounded classification.

  3. Flag unbounded and dynamic labels

    Review the counts with the application owners and mark each label as static, bounded dynamic, or unbounded. Static labels such as region, cluster, namespace and environment are the set Loki's label best practices favor. Dynamic labels are acceptable only when their value set is small and predictable. Unbounded labels, such as trace IDs, request IDs and per-user values, combine into very large numbers of streams, which the best-practices guidance warns leads to a large index and small chunks. The step is done when every label has a decision and the reason is written next to it.

  4. Remove or demote unbounded labels

    The platform engineer changes the shipper configuration so unbounded values are no longer set as index labels. The usual options are to drop the label, to keep the value inside the log line for filtering with line filters, or to move it to structured metadata if your Loki version and schema support it for that field. Apply the change in a non-production pipeline first and keep the previous configuration under version control so it can be restored. The step is done when the change is merged, deployed to the test pipeline, and the configuration diff is reviewed by someone other than the author.

  5. Verify stream counts after the change

    After the new configuration has run for a comparable period, check the active stream count for the tenant and compare it with the baseline from the inventory step. Confirm that the number of streams has dropped for the affected labels and that ingestion errors related to stream limits have not appeared. Check the ingestion and limits metrics described in the Loki monitoring documentation. The step is done when the stream count and ingestion metrics are recorded alongside the baseline, with any unexpected increase traced to a source.

  6. Verify query behavior and line filters

    Run the queries your teams rely on, such as dashboards and alert queries, against the changed streams. Queries that selected by a removed label now need to filter on the content of the log line or on structured metadata, so rewrite them and confirm that results match the pre-change output for the same time range. Check the query latency for the same queries before and after the change. The step is done when the agreed query set returns matching results, and each rewritten query is recorded with the owner who approved it.

  7. Document the label standard for the team

    The platform team writes a short label standard that lists the approved static labels, the criteria for any dynamic label, the labels that are forbidden in the pipeline, and the owner who approves exceptions. The standard is stored with the shipper configuration and linked from the team runbook so that new pipelines are reviewed against it. The step is done when the standard is reviewed by the application owners and the security or compliance contact who depends on log attribution, and when the review process for new labels is in place.

Decision path for each candidate label

Start with each candidate label and ask whether its value is bounded and stable. If not, it does not belong in the index. If it is, ask whether it identifies a stream, meaning the same series of log lines over time. Labels that do not identify a stream, but are still needed for exact selection, can be kept only when the set of values stays small. Everything else goes to structured metadata or is filtered in the line at query time, so streams and chunks stay healthy.

Each candidate label passes three checks before it becomes an index label.

Security and access considerations for label design

Labels are metadata, and in Loki that metadata is visible to anyone who can query a tenant. The cards below cover what should never become a label, how access is enforced in open-source Loki, and where label-based access control comes from.

Labels are visible to every reader

Anyone who can run a query against a tenant can list label names and values, so a label is never a private field. Treat label values as data that will appear in Grafana dropdowns, query results and any export. Before adding a label, ask whether every person with query access to that tenant should be able to see its values.

Multi-tenancy docs

Keep secrets out of labels

Tokens, passwords, API keys and session identifiers must not appear as labels or in the log line metadata you index. Redact them in the collector pipeline before Loki receives the log, for example in Grafana Alloy, so the values never reach object storage. Confirm the redaction rules with your security team and test them on sample logs.

Avoid personal and customer identifiers

Customer IDs, email addresses, account numbers and similar personal data create high-cardinality labels and can also expose individuals to anyone with query access. If an investigation needs them, keep them in structured metadata or the log line, and review your retention and deletion obligations for that data before ingestion starts.

Authentication sits in front of Loki

Loki has no built-in authentication layer. Put an authenticating reverse proxy such as nginx, HAProxy, OAuth2 Proxy or Pomerium in front of the Loki endpoints, and set the tenant header only from the proxy so users cannot choose another tenant. Confirm the proxy also protects the write path and the ruler API.

Authentication docs

Label-based access control is an enterprise feature

Restricting which label values a user can read inside one tenant is part of Grafana Enterprise Logs, not open-source Loki. In open-source Loki, separation relies on tenant IDs set through X-Scope-OrgID, so teams that need finer control must either split data into tenants or evaluate the commercial product.

Enterprise Logs docs

Review label design with the access model

Sort labels by who needs to see them and whether they belong in separate tenants. Environment or cluster names often justify a tenant boundary, while labels that differ only by team usually do not. Write the access model and label list down together, then review both when a new team or data source is onboarded.

Questions teams ask before changing Loki labels

What do labelling mistakes actually cost in Loki?

Labelling mistakes cost you in two places: the size of the index and the size of your chunks. Each unique combination of label values creates a stream, and too many combinations produce a large index and small chunks, which slows queries and raises storage overhead. The main drivers are the number of distinct values on each label, how many labels combine with each other, and how many new values appear over time, such as pod names or request IDs. Cost depends on your object storage pricing and query load, so measure stream count and chunk size in your own cluster before deciding how far to correct the design.

How long does a Loki label review take?

The length of a label review depends on how many log sources you ship, how many labels are already in use, how many teams query the data, and whether any shipper configuration needs to change. A small cluster with one shipper and a handful of applications is far simpler than a multi-tenant cluster with dozens of Kubernetes namespaces and several log agents. Ask any provider for a written scope that lists the sources, labels and environments covered, and treat any duration without that scope as a guess. Your own inventory of streams and shipper configs is the fastest way to size the work.

Can our internal team review Loki labels without outside help?

Yes, many teams can, provided someone understands both Loki's data model and the applications producing the logs. The work involves reviewing current label sets, deciding which labels stay static and bounded, moving dynamic values into structured metadata or line filters, and updating shipper configuration. The skills most often missing are knowledge of the Loki label guidance and experience with the shipper, such as Grafana Alloy. Plan for someone to own the changes after the review, because label changes affect existing dashboards, alerts and queries that depend on the old names.

What input do we need to give for a label review?

Prepare three things: representative log samples from each source, the configuration of every shipper that sends logs (such as Grafana Alloy, Fluent Bit or the Docker logging driver), and the list of tenants and teams that query the cluster. Samples show which fields vary between lines, shipper configs show which labels are being set and where, and the tenant list shows who depends on current label names. It also helps to export the label names and approximate stream counts you already see, plus the dashboards and alert rules that use them, so the review can account for existing queries.

Which label changes need a rollout plan?

Any change that renames or removes a label, or changes which values become labels, needs a rollout plan. Old and new log streams will coexist for a period, so queries that filter on the old label will return partial results across the switch. Plan to update Grafana dashboards, LogQL alert rules and any saved queries in the same window, and confirm with each tenant owner before the change. Check the Loki documentation for the version you run, because behavior for structured metadata and default OpenTelemetry labels depends on configuration.

Does moving data into structured metadata change who can see it?

Structured metadata is stored with the log lines and is not part of the index labels, so it does not change tenant isolation on its own. Tenant separation in Loki is set by the X-Scope-OrgID header when authentication is enabled, and access control must be enforced by an authenticating reverse proxy in front of Loki. Confirm with your security team how sensitive fields such as user IDs are handled, because moving a field from a label to metadata or a line changes how it is stored and queried, not whether it is protected.

When is outside help worth considering for Loki labels?

Outside help is worth considering when the cluster is large, several teams depend on shared label names, the label change must be coordinated with a Loki version upgrade, or your internal team has no one who can own the work after it ends. DeployOpen implements, configures, documents and supports self-hosted open-source platforms in your own infrastructure, so a label review can be scoped in writing with a defined set of deliverables. Ask any provider to name the sources, dashboards and tenants covered, and request a written quote based on that scope.

How DeployOpen reviews Loki labels

DeployOpen reviews label design as a fixed-scope engagement against your self-hosted Loki deployment, running in your own cloud accounts, data centers or air-gapped network. The review starts from the streams Loki actually creates today. We look at the labels attached by your log shippers, whether they come from Grafana Alloy, Fluent Bit, Fluentd, the Docker logging driver or OpenTelemetry, and at the static labels you intend to keep, such as cluster, namespace and environment. Each label is checked for whether its value set is bounded, who sets it, and what query pattern depends on it. The output is a written inventory that separates labels to keep, labels to move into structured metadata or line content, and labels to drop.

Before work starts, DeployOpen agrees the scope in writing: which clusters, tenants and log sources are in the review, which Loki version and index setup are in use, and what the deliverables are. Typical deliverables include the label inventory, a set of shipper configuration changes for Grafana Alloy or your other agents, a stream-count and chunk-size check against your current deployment, and a short runbook your team can repeat when a new application is onboarded. Ask for the acceptance criteria in the quote, including how changes are tested in a non-production tenant before they reach production. Because the fee follows from that written scope, the size of your log sources and the number of tenants are the main drivers to confirm up front.

Label design does not stay fixed once a team starts shipping new services, so DeployOpen also offers an optional retainer for ongoing support. Under a retainer, we can review new label proposals before they are deployed, watch stream growth after releases, and help your platform team tune shipper configuration as applications change. The retainer scope, response expectations and review cadence are agreed in writing, and should be checked against your own change process. Your team keeps ownership of the Loki cluster and its configuration throughout, and any changes we make are documented so they can be reviewed in your existing repositories.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.