Fix Alloy logfmt decode errors for JSON logs
Use stage.match to conditionally apply logfmt parsing only to lines
that don't start with '{'. This prevents error spam when JSON-formatted
logs are passed to the logfmt parser.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
16bfe06b7b
commit
13b21b09f2
1 changed files with 13 additions and 9 deletions
|
|
@ -102,18 +102,22 @@ data:
|
|||
}
|
||||
}
|
||||
|
||||
// Try to parse logfmt logs (e.g., Loki, Prometheus, Go services)
|
||||
// Silently skip lines that aren't valid logfmt
|
||||
stage.logfmt {
|
||||
mapping = {
|
||||
level = "level",
|
||||
ts = "ts",
|
||||
caller = "caller",
|
||||
component = "component",
|
||||
// Try to parse logfmt logs, but only for non-JSON lines
|
||||
// This prevents noisy decode errors when JSON logs hit the logfmt parser
|
||||
stage.match {
|
||||
selector = "{namespace=~\".+\"} |~ \"^[^{]\"" // Lines not starting with '{'
|
||||
|
||||
stage.logfmt {
|
||||
mapping = {
|
||||
level = "level",
|
||||
ts = "ts",
|
||||
caller = "caller",
|
||||
component = "component",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Drop the logfmt error label if parsing failed (prevents noisy errors)
|
||||
// Drop any error labels from parsing attempts (both JSON and logfmt)
|
||||
stage.label_drop {
|
||||
values = ["__error__", "__error_details__"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue