Drain Processor
contrib, k8s
Maintainers: @MikeGoldsmith, @atoulme, @martinjt
Source: opentelemetry-collector-contrib
Supported Telemetry
Overview
This processor annotates; it does not filter. Use the filter processor downstream to act on thelog.record.template attribute — for example, to drop entire classes of noisy logs by pattern.
How it works
Drain builds a parse tree from the token structure of log lines. Lines with similar structure are grouped into a cluster, and a template is derived by replacing variable tokens with<*> wildcards. As more logs arrive the templates become more accurate and stable.
Use the template string for filtering rules; it converges to the same value across instances given the same configuration and log patterns (see Deployment considerations).
Configuration
Parameters
Seeding
Seeding pre-populates the Drain tree before any live logs arrive. This is the primary mechanism for stable templates across restarts.seed_templates
Provide known template strings directly. The processor trains on each entry at startup, establishing clusters for those patterns immediately.
seed_logs
Provide raw example log lines. The processor trains on them at startup, letting Drain derive the templates itself. Useful when exact template strings are not known in advance.
Deployment considerations
Multiple collector instances
Each collector instance builds its Drain parse tree independently in memory. Two instances processing the same log patterns will converge on identical templates because the Drain algorithm is deterministic: given the same configuration and a representative sample of log forms, the same token structure produces the same template string. The main caveat is the early training phase. Before an instance has seen enough lines to abstract a wildcard (e.g. before"user alice logged in" and "user bob logged in" have both been observed), different instances may temporarily produce different templates for the same logical pattern. This is most noticeable at startup with low-volume or highly variable log streams.
Mitigations:
- Use
seed_templatesorseed_logsto pre-load known patterns at startup. With a comprehensive seed set, instances start in an already-converged state and live training only fills in the gaps. - Use
warmup_min_clustersto suppress annotation until the tree has stabilised, avoiding unstable templates reaching downstream processors.
Warmup suppression
Whenwarmup_min_clusters is set to a value greater than zero, the processor trains on every record from the start but does not write log.record.template until that many distinct clusters have been observed. Records pass through immediately — there is no buffering or added latency — they simply arrive at the next processor unannotated during the warmup window.
The warmup window is observable via otelcol_processor_incoming_items - otelcol_processor_drain_log_records_annotated — the difference represents records that passed through without a template attribute.
Metrics
The processor emits the following internal telemetry metrics:Output attributes
The processor sets the following attributes on each log record:
The attribute names are configurable via
template_attribute and params_attribute.
Semantic conventions: log.record.template aligns with the proposed OTel attribute in open-telemetry/semantic-conventions#1283 and #2064. These names may be updated if a convention is formally adopted.
Parameter extraction
Withextract_parameters: true the processor writes the body tokens at each <*> position of the matched template as a string slice attribute. The values appear in template order, one entry per <*>.
"user alice logged in from 10.0.0.1" and the matched template "user <*> logged in from <*>", the resulting attributes are:
- Extraction is positional and unnamed. No regex configuration is required.
- Body tokenisation matches the parse tree’s: whitespace plus any
extra_delimiters. - The parameter slice is only written when the template contains at least one
<*>. Fully literal templates (single-record clusters before abstraction) emit no slice. - During warmup suppression neither
log.record.templatenorlog.record.template.paramsis written.
Example pipeline
The following pipeline annotates logs with Drain templates and then drops known noisy patterns using the filter processor:body_field
body_field is a convenience for pipelines where the log body is a structured map and you do not have full control over how upstream processors shape it.
If you do control the pipeline, the preferred approach is a move operator in the filelog receiver (or equivalent) to promote the message field back to a plain string body before the drain processor sees the record:
body_field to the map key whose value should be fed to Drain:
{"level": "info", "message": "user alice logged in from 10.0.0.1"}, only the message value is fed to Drain. The full body is used unchanged if the field is absent or the body is not a map.
Note:body_fieldonly supports a single top-level key. Full OTTL path expressions (e.g.body["event"]["message"]) are not supported and are noted as a future extension.
Snapshot persistence
Whenstorage is set to the ID of a storage extension, the processor saves and restores the Drain tree state across restarts. This eliminates the need for seeding and warmup in most deployments.
Lifecycle
- Startup: the processor attempts to load a snapshot from storage. If a valid snapshot is found,
seed_templatesandseed_logsare skipped (they are already incorporated in the snapshot). If the loaded tree has enough clusters to satisfywarmup_min_clusters, warmup is also skipped. - Runtime: if
save_intervalis set, the tree is snapshotted periodically. A hash check avoids redundant writes when the tree has not changed. - Shutdown: a final snapshot is always saved.
Shared storage for scaled deployments
With a shared storage backend (Redis, database), periodic saves allow new instances joining a scaled deployment to load a tree that was trained by already-running instances. This avoids the cold-start problem where newly added collectors must rebuild the tree from scratch. Multiple instances writing to the same storage key is safe — all instances see similar log traffic and converge on similar trees, so any snapshot is useful as a starting point. The hash check reduces redundant writes across instances. To clear the snapshot and force a fresh start (e.g. after changing Drain parameters), delete the storage data for the processor.Future extensions
- OTTL body extraction: support full OTTL path expressions for
body_fieldinstead of a single top-level key name. - Multi-instance tree merging: gossip-based tree merging for consistent templates across horizontally scaled deployments.
Last generated: 2026-07-20