Skip to main content

Drain Processor

Status Available in: contrib, k8s Maintainers: @MikeGoldsmith, @atoulme, @martinjt Source: opentelemetry-collector-contrib

Supported Telemetry

Logs

Overview

This processor annotates; it does not filter. Use the filter processor downstream to act on the log.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.
Empty and whitespace-only entries in both lists are silently skipped.

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_templates or seed_logs to 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_clusters to suppress annotation until the tree has stabilised, avoiding unstable templates reaching downstream processors.

Warmup suppression

When warmup_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.
Once the threshold is reached, all subsequent records are annotated normally. Records that passed through during warmup are not re-annotated.

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

With extract_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 <*>.
Given the body "user alice logged in from 10.0.0.1" and the matched template "user <*> logged in from <*>", the resulting attributes are:
Notes:
  • 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.template nor log.record.template.params is 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:
If you cannot do that — for example, logs arrive via OTLP already structured — set body_field to the map key whose value should be fed to Drain:
Given a log body {"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_field only 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

When storage 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_templates and seed_logs are skipped (they are already incorporated in the snapshot). If the loaded tree has enough clusters to satisfy warmup_min_clusters, warmup is also skipped.
  • Runtime: if save_interval is 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.
If the snapshot is corrupt or cannot be loaded, the processor logs a warning and falls back to seeding as if no snapshot existed.

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_field instead 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