This is documentation for the next version of Grafana Alloy Documentation. For the latest stable release, go to the latest version.
otelcol.encoding.jsonlog
EXPERIMENTAL: This is an experimental component. Experimental components are subject to frequent breaking changes, and may be removed with no equivalent replacement. To enable and use an experimental component, you must set the
stability.levelflag toexperimental.
otelcol.encoding.jsonlog encodes and decodes OpenTelemetry log records as JSON.
It exposes a handler that compatible otelcol components can use to marshal and unmarshal logs.
Note
otelcol.encoding.jsonlogis a wrapper over the upstream OpenTelemetry Collectorjsonlogencodingextensionextension. Grafana Labs redirects bug reports or feature requests to the upstream repository when necessary.
You can specify multiple otelcol.encoding.jsonlog components by giving them different labels.
Usage
otelcol.encoding.jsonlog "<LABEL>" {
}Arguments
You can use the following arguments with otelcol.encoding.jsonlog:
The array_mode argument controls the JSON document shape.
When array_mode is true, unmarshaled input must be a JSON array of objects, and marshaled output is a JSON array.
When array_mode is false, unmarshaled input can be a single JSON object or a stream of concatenated JSON objects, including newline-delimited JSON.
Marshaled output contains one JSON object per line when array_mode is false and there are multiple log records.
The mode argument supports the following values:
bodymarshals each log record’s body and requires the body to be a map.body_with_inline_attributesmarshals each log record as an object containing itsbody,resourceAttributes, andlogAttributesfields when those fields aren’t empty.
The mode argument affects marshaling only.
During unmarshaling, the component stores each JSON object as a log record body.
The parse_ints argument affects unmarshaling only.
By default, the component decodes every JSON number as a float64, so integers larger than 2^53 can lose precision.
When parse_ints is true, the component decodes integer literals within the int64 range as int64, including those in nested objects and arrays.
For example, with the input {"id": 9007199254740993}, id is 9007199254740992 when parse_ints is false, and 9007199254740993 when it’s true.
Numbers with a fraction, such as 1.0, numbers with an exponent, such as 1e3, and values outside the int64 range are always decoded as float64.
Enabling parse_ints adds processing overhead.
Blocks
The otelcol.encoding.jsonlog component doesn’t support any blocks.
You can configure this component with arguments.
Exported fields
The following fields are exported and can be referenced by other components:
Component health
otelcol.encoding.jsonlog is only reported as unhealthy if given an invalid configuration.
Debug information
otelcol.encoding.jsonlog doesn’t expose any component-specific debug information.
Debug metrics
otelcol.encoding.jsonlog doesn’t expose any component-specific debug metrics.
Examples
otelcol.receiver.awss3
This example uses otelcol.encoding.jsonlog to decode newline-delimited JSON log records from S3 objects with keys that end in .jsonl.
The receiver forwards the decoded logs to otelcol.exporter.debug:
otelcol.encoding.jsonlog "default" {
array_mode = false
}
otelcol.receiver.awss3 "default" {
start_time = "2024-01-01 01:00"
end_time = "2024-01-02"
s3downloader {
region = "us-west-1"
s3_bucket = "mybucket"
s3_prefix = "logs"
}
encoding {
extension = otelcol.encoding.jsonlog.default.handler
suffix = ".jsonl"
}
output {
logs = [otelcol.exporter.debug.default.input]
}
}
otelcol.exporter.debug "default" {}

