Menu

This is documentation for the next version of Alloy. For the latest stable release, go to the latest version.

Public preview

otelcol.receiver.filelog

Public preview: This is a public preview component. Public preview components are subject to breaking changes, and may be replaced with equivalent functionality that cover the same use case. The stability.level flag must be set to public-preview or below to use the component.

otelcol.receiver.filelog reads log entries from files and forwards them to other otelcol.* components.

Note

otelcol.receiver.filelog is a wrapper over the upstream OpenTelemetry Collector filelog receiver. Bug reports or feature requests will be redirected to the upstream repository, if necessary.

You can specify multiple otelcol.receiver.filelog components by giving them different labels.

Usage

alloy
otelcol.receiver.filelog "<LABEL>" {
  include = [...]
  output {
    logs    = [...]
  }
}

Arguments

You can use the following arguments with otelcol.receiver.filelog:

NameTypeDescriptionDefaultRequired
includelist(string)A list of glob patterns to include files.yes
excludelist(string)A list of glob patterns to exclude files that would be included by the include patterns.[]no
poll_intervaltime.DurationThe interval at which the file is polled for new entries.200msno
max_concurrent_filesintThe maximum number of files to read concurrently.10no
max_batchesintThe maximum number of batches to process concurrently.10no
start_atstringThe position to start reading the file from.beginningno
fingerprint_sizeunits.Base2BytesThe size of the fingerprint used to detect file changes.1KiBno
max_log_sizeunits.Base2BytesThe maximum size of a log entry.1MiBno
encodingstringThe encoding of the log file.utf-8no
force_flush_periodtime.DurationThe period after which logs are flushed even if the buffer is not full.500msno
delete_after_readboolWhether to delete the file after reading.falseno
compressionstringThe compression type used for the log file.``no
acquire_fs_lockboolWhether to acquire a file system lock while reading the file (Unix only).falseno
attributesmap(string)A map of attributes to add to each log entry.{}no
resourcemap(string)A map of resource attributes to associate with each log entry.{}no
exclude_older_thantime.DurationExclude files with a modification time older than the specified duration.0sno
include_file_record_numberboolWhether to include the file record number in the log entry.falseno
include_file_nameboolWhether to include the file name in the log entry.trueno
include_file_pathboolWhether to include the file path in the log entry.falseno
include_file_name_resolvedboolWhether to include the resolved file name in the log entry.falseno
include_file_path_resolvedboolWhether to include the resolved file path in the log entry.falseno
include_file_owner_nameboolWhether to include the file owner’s name in the log entry.falseno
include_file_owner_group_nameboolWhether to include the file owner’s group name in the log entry.falseno
preserve_leading_whitespacesboolPreserves leading whitespace in messages when set to true.falseno
preserve_trailing_whitespacesboolPreserves trailing whitespace in messages when set to true.falseno
operatorslists(map(string)A list of operators used to parse the log entries.[]no

encoding must be one of utf-8, utf-16le, utf-16be, ascii, big5, or nop. Refer to the upstream receiver documentation for more details.

start_at must be one of beginning or end. The header block may only be used if start_at is beginning.

compression must be either `` or gzip.

operators

The operators list is a list of stanza operators that transform the log entries after they have been read.

For example, if container logs are being collected you may want to utilize the stanza container parser operator to add relevant attributes to the log entries.

alloy
otelcol.receiver.filelog "default" {
    ...
    operators = [
      {
        type = "container"
      }
    ]
}

Blocks

The following blocks are supported inside the definition of otelcol.receiver.filelog:

HierarchyBlockDescriptionRequired
outputoutputConfigures where to send received telemetry data.yes
multilinemultilineConfigures rules for multiline parsing of log messagesno
headerheaderConfigures rules for parsing a log header lineno
retry_on_failureretry_on_failureConfigures the retry behavior when the receiver encounters an error downstream in the pipeline.no
debug_metricsdebug_metricsConfigures the metrics that this component generates to monitor its state.no
ordering_criteriaordering_criteriaConfigures the order in which log files are processed.no
ordering_criteria > sort_bysort_byConfigures the fields to sort by within the ordering critera.yes

The > symbol indicates deeper levels of nesting. For example, ordering_criteria > sort_by refers to a sort_by block defined inside a ordering_criteria block.

output

Required

The output block configures a set of components to forward resulting telemetry data to.

The following arguments are supported:

NameTypeDescriptionDefaultRequired
logslist(otelcol.Consumer)List of consumers to send logs to.[]no
metricslist(otelcol.Consumer)List of consumers to send metrics to.[]no
traceslist(otelcol.Consumer)List of consumers to send traces to.[]no

You must specify the output block, but all its arguments are optional. By default, telemetry data is dropped. Configure the metrics, logs, and traces arguments accordingly to send telemetry data to other components.

debug_metrics

The debug_metrics block configures the metrics that this component generates to monitor its state.

The following arguments are supported:

NameTypeDescriptionDefaultRequired
disable_high_cardinality_metricsbooleanWhether to disable certain high cardinality metrics.trueno
levelstringControls the level of detail for metrics emitted by the wrapped collector."detailed"no

disable_high_cardinality_metrics is the Grafana Alloy equivalent to the telemetry.disableHighCardinalityMetrics feature gate in the OpenTelemetry Collector. It removes attributes that could cause high cardinality metrics. For example, attributes with IP addresses and port numbers in metrics about HTTP and gRPC connections are removed.

Note

If configured, disable_high_cardinality_metrics only applies to otelcol.exporter.* and otelcol.receiver.* components.

level is the Alloy equivalent to the telemetry.metrics.level feature gate in the OpenTelemetry Collector. Possible values are "none", "basic", "normal" and "detailed".

The header block configures logic for parsing a log header line into additional attributes added to each log entry. It may only be used when start_at is set to beginning. The following arguments are supported:

NameTypeDescriptionDefaultRequired
metadata_operatorslists(map(string)A list of operators used to parse metadata from the header.yes
patternstringA regular expression that matches the header line.yes

If a header block is not set, no log lines will be treated as header metadata.

The metadata_operators list is a list of stanza operators that parses metadata from the header. Any attributes created from the embedded operators pipeline will be applied to all log entries in the file.

For example, you might use a regex_parser to process a header line that has been identified by the pattern expression. The following example shows a fictitious header line, and then the header block that would parse an environment attribute from it.

text
HEADER_IDENTIFIER env="production"
...
alloy
otelcol.receiver.filelog "default" {
    ...
    header {
      pattern = '^HEADER_IDENTIFIER .*$'
      metadata_operators = [
        {
          type = "regex_parser"
          regex = 'env="(?P<environment>.+)"'
        }
      ]
    }
}

multiline

The multiline block configures logic for splitting incoming log entries. The following arguments are supported:

NameTypeDescriptionDefaultRequired
line_end_patternstringA regular expression that matches the end of a log entry.yes*
line_start_patternstringA regular expression that matches the beginning of a log entry.yes*
omit_patternboolOmit the start/end pattern from the split log entries.falseno

A multiline block must contain either line_start_pattern or line_end_pattern.

If a multiline block isn’t set, log entries will not be split.

ordering_criteria

The ordering_criteria block configures the order in which log files discovered will be processed. The following arguments are supported:

NameTypeDescriptionDefaultRequired
group_bystringA named capture group from the regex attribute used for grouping pre-sort.""no
regexstringA regular expression to capture elements of log files to use in ordering calculations.""no
top_nintThe number of top log files to track when using file ordering.1no

sort_by

The sort_by repeatable block configures the way the fields parsed in the ordering_criteria block will be applied to sort the discovered log files. The following arguments are supported:

NameTypeDescriptionDefaultRequired
sort_typestringThe type of sorting to apply.yes
ascendingboolWhether to sort in ascending order.trueno
layoutstringThe layout of the timestamp to be parsed from a named regex capture group.""no
locationstringThe location of the timestamp.UTCno
regex_keystringThe named capture group from the regex attribute to use for sorting.""no

sort_type must be one of numeric, lexicographic, timestamp, or mtime. When using numeric, lexicographic, or timestamp sort_type, a named capture group defined in the regex attribute in ordering_criteria must be provided in regex_key. When using mtime sort_type, the file’s modified time will be used to sort.

The location and layout arguments are only applicable when sort_type is timestamp.

The location argument specifies a Time Zone identifier. The available locations depend on the local IANA Time Zone database. Refer to the list of tz database time zones in Wikipedia for a non-comprehensive list.

retry_on_failure

The retry_on_failure block configures the retry behavior when the receiver encounters an error downstream in the pipeline. A backoff algorithm is used to delay the retry upon subsequent failures. The following arguments are supported:

NameTypeDescriptionDefaultRequired
enabledboolIf set to true and an error occurs, the receiver will pause reading the log files and resend the current batch of logs.falseno
initial_intervaldurationThe time to wait after first failure to retry.1sno
max_elapsed_timedurationThe maximum age of a message before the data is discarded.5mno
max_intervaldurationThe maximum time to wait after applying backoff logic.30sno

If max_elapsed_time is set to 0 data is never discarded.

Exported fields

otelcol.receiver.filelog doesn’t export any fields.

Component health

otelcol.receiver.filelog is only reported as unhealthy if given an invalid configuration.

Debug metrics

otelcol.receiver.filelog doesn’t expose any component-specific debug metrics.

Example

This example reads log entries using the otelcol.receiver.filelog receiver and they are logged by a otelcol.exporter.debug component. It expects the logs to start with an ISO8601 compatible timestamp and parses it from the log using the regex_parser operator.

alloy
otelcol.receiver.filelog "default" {
  include = ["/var/log/*.log"]
  operators = [{
    type = "regex_parser",
    regex = "^(?P<timestamp>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3,6}Z)",
    timestamp = {
      parse_from = "attributes.timestamp",
      layout = "%Y-%m-%dT%H:%M:%S.%fZ",
      location = "UTC",
    },
  }]
  output {
      logs = [otelcol.exporter.debug.default.input]
  }
}

otelcol.exporter.debug "default" {}

Compatible components

otelcol.receiver.filelog can accept arguments from the following components:

Note

Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. Refer to the linked documentation for more details.