OpsCanary
Back to daily brief
observabilityloggingPractitioner

Mastering Labels in Grafana Loki for Effective Logging

5 min read Grafana DocsApr 27, 2026
Share
PractitionerHands-on experience recommended

Labels are a crucial part of Grafana Loki. They allow you to organize and group log messages into log streams, making it easier to manage and query your logs. Each log stream consists of log messages that share all the same labels, which is fundamental for efficient log retrieval.

In Loki, the content of each log line isn't indexed. Instead, log entries are grouped into streams indexed by labels. When you perform a search, Loki first identifies the relevant stream based on your chosen labels, then iterates through the logs in that stream to execute your query. This mechanism emphasizes the importance of choosing the right labels. You can configure parameters like discover_service_name to customize the labels used for creating the service name, and default_resource_attributes_as_index_labels to manage which resource attributes are stored as labels. However, be cautious with high cardinality; it can lead to performance issues as it causes Loki to create a large index and flush numerous tiny chunks to the object store.

In production, you need to be strategic about the labels you use. Stick to low-cardinality values that accurately describe your log sources. The default limit of 15 index labels means you should be selective about which resource attributes to include. Avoid high-cardinality labels like k8s.pod.name and service.instance.id, and instead, consider converting them to structured metadata. This approach will help you maintain performance and efficiency in your logging setup.

Key takeaways

  • Use labels to group log messages into log streams for better organization.
  • Limit the number of index labels to avoid performance degradation.
  • Convert high-cardinality labels to structured metadata for efficient querying.
  • Configure `discover_service_name` to customize service name labels.
  • Be selective with resource attributes stored as labels to optimize log indexing.

Why it matters

In production, effective use of labels in Grafana Loki can drastically improve log search performance and reduce resource consumption. This directly impacts your ability to troubleshoot and monitor applications efficiently.

Code examples

plaintext
service_name
plaintext
{namespace="mynamespace", cluster="cluster123" filename="/var/log/myapp.log"}
plaintext
app.kubernetes.io/name

When NOT to use this

High cardinality can lead to significant performance degradation. If your logging needs involve frequent searches on high-cardinality data, consider using structured metadata instead of relying solely on labels.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.