Use it when logs need structure for search and correlation.
Log Parsing and Enrichment
Log parsing extracts fields from raw lines (JSON, logfmt, regex, grok) and enrichment adds context (Kubernetes metadata, host, environment, GeoIP) in agents or pipelines.
1. Test a parser on a sample, e.g. Fluent Bit fluent-bit -c fluent-bit.conf --dry-run / Vector vector test.
2. Fields present in the backend.
3. Parse failures counted?
4. Enrichment labels (namespace, pod).
5. Original message kept.
raw line → parser → fields → enrichment → indexed
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Search for a field from a parsed line in the backend. Watch parse failure rates after application releases.
Step 2 Common failures Narrow the fault
A format change in the application breaks regex parsers silently. Using ingestion time instead of event time misorders logs. Enrichment that calls the Kubernetes API for every line overloads it without caching.
Parse as early as practical but keep the original message. Test parsers against real samples. Add Kubernetes metadata via the agent.
fluent-bit -c fluent-bit.conf --dry-run— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool check config prometheus.yml— config valid
ReferenceWhat it is1 section · depth on demand
How it works
Agents such as Fluent Bit, Vector, Promtail or the OpenTelemetry collector read files or streams, apply parsers and filters, and forward records. Kubernetes filters query the API for Pod metadata.
ReferenceImportant terms & boundaries3 sections · depth on demand
Parsing example (Fluent Bit)
[PARSER]
Name nginx
Format regex
Regex ^(?<remote>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+) (?<path>[^"]*?) HTTP/[^"]*" (?<code>\d{3}) (?<size>\d+)
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[FILTER]
Name kubernetes
Match kube.*
Documented example, not captured output. Parse as early as possible, add environment/host/Kubernetes metadata, redact secrets and personal data, and keep the original message for evidence when needed.
In depth
Parse once, at ingest
Turning 10.0.4.17 - - [27/Nov/2026:09:14:03 +0100] "GET /cart HTTP/1.1" 502 157 0.812 into fields at ingest means every later query can filter status = 502 cheaply; parsing at query time repeats the work on every search.
Prefer structured sources over regex
| Source | Approach |
|---|---|
| Your own services | Log JSON (no parsing needed) |
| Nginx/Apache | Configure a JSON log_format, or use the agent's built-in parser |
| Kubernetes container logs | CRI/docker parser first (strips the runtime prefix), then the app format |
| Legacy text formats | Regex or pattern parser, with tests |
Multi-line events
Java and Python stack traces span many lines. Join them at the agent with a multi-line parser (start pattern = line beginning with a timestamp; continuation = lines starting with whitespace, at , Caused by:), or better, emit them as a single JSON field.
Enrichment that is worth it
| Enrichment | Source |
|---|---|
| Kubernetes namespace, pod, container, labels | Kubernetes filter / k8sattributes |
| Host, region, environment | Agent configuration |
| GeoIP for client IP | GeoIP database (check privacy requirements) |
| Service owner/team | Lookup table keyed by service name |
Event time
Map the parsed timestamp to the record's time (Time_Key / Time_Format in Fluent Bit, timestamp in OpenTelemetry). If parsing the time fails, many agents fall back to ingestion time silently and logs appear out of order after a backlog.
Watching for breakage
Application releases change log formats. Count parse failures and alert on a sudden rise:
rate(fluentbit_filter_drop_records_total[5m]) > 0
Route unparseable lines to a separate stream (or keep the raw line in a field) instead of dropping them, so a format change loses structure but not data.
Common mistakes
- Parsing at query time for every query instead of at ingest.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.