2. Processing pipelines #
Filtering, parsing (JSON, Regex), and relabeling.
Enrich and filter logs #
Raw logs often lack context and consume too much storage. The loki.process component allows you to define sophisticated processing pipelines. You can embed stages to extract fields via JSON or Regex parsing, use these fields to create new dynamic labels, filter (drop) irrelevant lines (like HTTP healthchecks), or even rewrite the log content itself.
Best Practice: Drastically limit the number of labels extracted to Loki. Only extract global and static fields as labels (e.g.,env,app,level). For other fields (dynamic business values), leave them in the log line and use LogQL filters (e.g.,| json) at query time.
Common Mistake: Promoting a highly variable field (like an IP address, atrace_id, or a transactionuuid) as a label. This mistake will crush the performance of your Loki instance.
loki.process "filter_logs" {
forward_to = [loki.write.default.receiver]
// JSON Parsing
stage.json {
expressions = { level = "log_level", app = "app_name" }
}
// Secure label creation
stage.labels {
values = { level = null, app = null }
}
// Filter out useless logs
stage.drop {
source = "level"
value = "debug"
}
}My progress
Sign in to track your progress and take notes. Sign in
Course Glossary
Grafana Alloy
An open-source, vendor-neutral telemetry collector designed to replace Grafana Agent, fully compatible with OpenTelemetry (OTel).
Recommended Articles
Référence des Composants Grafana Alloy
Un guide de référence complet sur tous les composants disponibles dans Grafana Alloy, organisé pa...
OpenTelemetry Collector, Grafana Alloy et Bindplane : comparer trois approches des pipelines de télémétrie
Comparatif détaillé de trois façons de gérer des pipelines de télémétrie : l'OpenTelemetry Collec...
Grafana Alloy : Collecte et Transformation de Télémétrie
Apprenez à utiliser Grafana Alloy pour collecter, transformer et acheminer logs, métriques et tra...
Collecter des logs vers Loki : Alloy, Promtail, Docker et OpenTelemetry
Envoyer des logs vers Loki : Grafana Alloy, Promtail, driver Docker, OTLP, bons labels, parsing e...
Grafana Alloy vs Grafana Agent vs Promtail : Lequel choisir ?
Découvrez l'évolution des collecteurs de télémétrie de l'écosystème Grafana. Comparatif détaillé ...
Grafana Alloy: Trace Management with Tempo
Dive into distributed trace processing. Learn how to ingest OTLP, Jaeger, or Zipkin traces with G...
La stack LGTM (Loki, Grafana, Tempo, Mimir) : architecture et mise en place
Comprendre la stack LGTM de Grafana Labs : Loki pour les logs, Grafana pour la visualisation, Tem...
Grafana Alloy: Introduction and Architecture
Discover the fundamental concepts of Grafana Alloy, the transition from the static Agent to Alloy...
Grafana Alloy: Understanding and exploiting the User Interface (UI)
Discover how to enable, secure, and use Grafana Alloy's built-in web interface to visualize your ...