Filelog Receiver
contrib, k8s
Maintainers: @andrzej-stencel, @paulojmdias, @VihasMakwana, @braydonk
Source: opentelemetry-collector-contrib
Supported Telemetry
Overview
Configuration
Note that by default, no logs will be read from a file that is not actively being written to because
start_at defaults to end.
Operators
Each operator performs a simple responsibility, such as parsing a timestamp or JSON. Chain together operators to process logs into a desired format.- Every operator has a
type. - Every operator can be given a unique
id. If you use the same type of operator more than once in a pipeline, you must specify anid. Otherwise, theiddefaults to the value oftype. - Operators will output to the next operator in the pipeline. The last operator in the pipeline will emit from the receiver. Optionally, the
outputparameter can be used to specify theidof another operator to which logs will be passed directly. - Only parsers and general purpose operators should be used.
Multiline configuration
If set, themultiline configuration block instructs the file_input operator to split log entries on a pattern other than newlines.
The multiline configuration block must contain exactly one of line_start_pattern or line_end_pattern. These are regex patterns that
match either the beginning of a new log entry, or the end of a log entry.
The omit_pattern setting can be used to omit the start/end pattern from each entry.
Supported encodings
Other less common encodings are supported on a best-effort basis. See https://www.iana.org/assignments/character-sets/character-sets.xhtml for other encodings available.
Header Metadata Parsing
To enable header metadata parsing, thefilelog.allowHeaderMetadataParsing feature gate must be set, and start_at must be beginning.
If set, the file input operator will attempt to read a header from the start of the file. Each header line must match the header.pattern pattern. Each line is emitted into a pipeline defined by header.metadata_operators. Any attributes on the resultant entry from the embedded pipeline will be merged with the attributes from previous lines (attribute collisions will be resolved with an upsert strategy). After all header lines are read, the final merged header attributes will be present on every log line that is emitted for the file.
The header lines are not emitted by the receiver.
Additional Terminology and Features
- An entry is the base representation of log data as it moves through a pipeline. All operators either create, modify, or consume entries.
- A field is used to reference values in an entry.
- A common expression syntax is used in several operators. For example, expressions can be used to filter or route entries.
Parsers with Embedded Operations
Many parsers operators can be configured to embed certain followup operations such as timestamp and severity parsing. For more information, see complex parsers.Time parameters
All time parameters must have the unit of time specified. e.g.:200ms, 1s, 1m.
Log Rotation
File Log Receiver can read files that are being rotated. It supports both common rotation strategies: move/create (the file is renamed and a new file is created) and copy/truncate (the file is copied to a backup and the original is truncated). The receiver tracks files by their internal identity (inode) and content fingerprint, allowing it to handle both strategies transparently and continue reading data even if the new filename no longer matches theinclude pattern.
File Attribute Behavior During Rotation
The receiver handles file attributes differently depending on whether rotated files match yourinclude pattern:
Rotated files NOT matching the include pattern:
When a file is rotated and the rotated filename no longer matches the include pattern, the receiver preserves the original file attributes (e.g., log.file.name, log.file.path). This ensures logs read from the rotated file continue to be associated with their original file identity.
Example: With include: /var/log/pods/*/*/0.log, when 0.log is rotated to 0.log.20260115-120000, logs from the rotated file will still report log.file.name=0.log.
Rotated files matching the include pattern:
When a file is rotated and the rotated filename continues to match the include pattern, the receiver reports the new rotated filename in file attributes. This is expected behavior that prevents duplicate metrics when tracking per-file consumption.
Example: With include: /var/log/pods/*/*/*.log*, when 0.log is rotated to 0.log.20260115-120000, logs from the rotated file will report log.file.name=0.log.20260115-120000.
For more details, see issue #38454.
Handling Copytruncate Rotation
When log files are rotated using thecopytruncate strategy (where the file is copied and then truncated in place), the receiver can detect when a file has been truncated by comparing the stored offset with the current file size. The on_truncate setting controls how the receiver behaves when truncation is detected:
ignore(default): The receiver keeps the original offset and will not read any data until the file grows past the original offset. This prevents duplicate log ingestion when a file is rotated.read_whole_file: The receiver resets the offset to 0 and reads the entire file from the beginning. Use this mode when you want to ensure no data loss, even if it means potentially re-reading some logs.read_new: The receiver updates the offset to the current file size (the position after truncation). This allows reading new data that is written after the truncation without re-reading existing content.
- Use
ignorewhen you want to avoid duplicate logs and your log rotation strategy ensures that rotated files are properly renamed or moved. - Use
read_whole_filewhen data completeness is critical and you can tolerate duplicate logs, or when you have deduplication logic downstream. - Use
read_newwhen files are expected to be deleted after rotation and you want to read only new data written after the truncation point.
Example - Tailing a simple json file
Receiver ConfigurationExample - Tailing a plaintext file
Receiver ConfigurationExample - Multiline logs parsing
Receiver Configuration^Exception pattern is met.
Example - Reading compressed log files
Receiver Configurationcompression option to gzip.
When this option is set, all files ending with that suffix are scanned using a gzip reader that decompresses the file content
before scanning through it. Please note that if the compressed file is expected to be updated, the additional compressed logs must be appended to the
compressed file, rather than recompressing the whole content and overwriting the previous file.
Offset tracking
Thestorage setting allows you to define the proper storage extension for storing file offsets.
While the storage parameter can ensure that log files are consumed accurately, it is possible that
logs are dropped while moving downstream through other components in the collector.
For additional resiliency, see Fault tolerant log collection example
Here is some of the information the file log receiver stores:
- The number of files it is currently tracking (
knownFiles). - For each file being tracked:
- The fingerprint of the file (
Fingerprint.first_bytes). - The byte offset from the start of the file, indicating the position in the file from where the
file log receiver continues reading the file (
Offset). - An arbitrary set of file attributes, such as the name of the file (
FileAttributes).
- The fingerprint of the file (
Archiving
Ifpolls_to_archive setting is used in conjunction with storage setting, file offsets older than three poll cycles are stored on disk rather than being discarded. This feature enables the receiver to remember file for a longer period and also aims to use limited amount of memory.
This is useful when exclude_older_than setting is used and the user wants the receiver to remember offsets of files for longer period of times. This helps prevent duplication if a file is modified after the exclude_older_than duration has passed.
Note that if the polls_to_archive setting is used without specifying storage, the receiver will revert to the default behavior i.e. purge the record of readers that have existed for 3 generations.
Troubleshooting
Tracking symlinked files
If the receiver is being used to track a symlinked file and the symlink target is expected to change frequently, make sure to set the value of thepoll_interval setting to something lower than the symlink update frequency.
Telemetry metrics
Enabling Collector metrics will also provide telemetry metrics for the state of the receiver’s file consumption. Specifically, theotelcol_fileconsumer_open_files and otelcol_fileconsumer_reading_files metrics
are provided.
Feature Gates
filelog.protobufCheckpointEncoding
When this feature gate is enabled, the receiver uses protobuf encoding for checkpoint storage instead of JSON. This provides improved performance (~7x faster decoding) and reduced storage usage (~31% smaller).
The feature includes full backward compatibility:
- The receiver can always read both protobuf and JSON checkpoints regardless of the feature gate setting
- When the feature gate is enabled, new checkpoints are written in protobuf format
- When the feature gate is disabled, new checkpoints are written in JSON format
--feature-gates=filelog.protobufCheckpointEncoding
Schedule for this feature gate is:
- Introduce as
Alpha(disabled by default) inv0.148.0
Configuration
Example Configuration
Last generated: 2026-08-24