The OpenTelemetry Collector configuration:
receivers:
journald:
processors:
resource:
attributes:
- key: loki.format
value: json
action: insert
- key: deployment.environment
value: "dev"
action: insert
exporters:
loki:
endpoint: "https://loki.net/loki/api/v1/push"
sending_queue:
num_consumers: 5
queue_size: 10000
headers:
"X-Scope-OrgID": "index"
file:
path: /home/otelcol-contrib/temp.log
service:
pipelines:
logs:
receivers: [journald]
processors: [resource]
exporters: [loki]
Serializes out a JSON object to Loki that looks like this:
{
"resourceLogs": [
{
"resource": {
"attributes": [
{
"key": "loki.format",
"value": {
"stringValue": "json"
}
},
{
"key": "deployment.environment",
"value": {
"stringValue": "dev"
}
}
]
},
"scopeLogs": [
{
"scope": {},
"logRecords": [
{
"timeUnixNano": "1721831731222344000",
"observedTimeUnixNano": "1721831731422059659",
"body": {
"kvlistValue": {
"values": [
{
"key": "_SELINUX_CONTEXT",
"value": {
"stringValue": "unconfinedn"
}
},
{
"key": "_SYSTEMD_SLICE",
"value": {
"stringValue": "system.slice"
}
},
{
"key": "_HOSTNAME",
"value": {
"stringValue": "hostname-dev"
}
},
{
"key": "_SYSTEMD_CGROUP",
"value": {
"stringValue": "/system.slice/otelcol-contrib.service"
}
},
{
"key": "_CAP_EFFECTIVE",
"value": {
"stringValue": "0"
}
},
{
"key": "_PID",
"value": {
"stringValue": "2262330"
}
},
{
"key": "SYSLOG_FACILITY",
"value": {
"stringValue": "3"
}
},
{
"key": "_EXE",
"value": {
"stringValue": "/usr/bin/otelcol-contrib"
}
},
{
"key": "PRIORITY",
"value": {
"stringValue": "6"
}
},
{
"key": "SYSLOG_IDENTIFIER",
"value": {
"stringValue": "otelcol-contrib"
}
},
{
"key": "_TRANSPORT",
"value": {
"stringValue": "stdout"
}
},
{
"key": "_SYSTEMD_UNIT",
"value": {
"stringValue": "otelcol-contrib.service"
}
},
{
"key": "_UID",
"value": {
"stringValue": "997"
}
},
{
"key": "_SYSTEMD_INVOCATION_ID",
"value": {
"stringValue": "231cd2139b2f4664b755d43b4690aef0"
}
},
{
"key": "_GID",
"value": {
"stringValue": "997"
}
},
{
"key": "_STREAM_ID",
"value": {
"stringValue": "8a194d71567d4ae4b4752a9f132eb336"
}
},
{
"key": "_MACHINE_ID",
"value": {
"stringValue": "5fca68f59b9583a46efa7b9f6697ef74"
}
},
{
"key": "_BOOT_ID",
"value": {
"stringValue": "f0d1b58e375844c3961c527ffc365e6c"
}
},
{
"key": "_CMDLINE",
"value": {
"stringValue": "/usr/bin/otelcol-contrib --config=/etc/otelcol- contrib/config.yaml"
}
},
{
"key": "__MONOTONIC_TIMESTAMP",
"value": {
"stringValue": "598265666336"
}
},
{
"key": "_COMM",
"value": {
"stringValue": "otelcol-contrib"
}
},
{
"key": "MESSAGE",
"value": {
"stringValue": "2024-07-24T14:35:31.222Ztinfo[email protected]/service.go:270tShutdown complete."
}
},
{
"key": "__CURSOR",
"value": {
"stringValue": "s=92ed14a0f4d04f8f9b315bb73d09e814;i=20f19;b=f0d1b58e375844c3961c527ffc365e6c;m=8b4b699b20;t=61dff30b3d748;x=3a5de1616420ef73"
}
}
]
}
},
"traceId": "",
"spanId": ""
},
{
"timeUnixNano": "1721831731241174000",
"observedTimeUnixNano": "1721831731422135940",
"body": {
"kvlistValue": {
"values": [
{
"key": "UNIT",
"value": {
"stringValue": "otelcol-contrib.service"
}
},
{
"key": "CODE_FUNC",
"value": {
"stringValue": "unit_log_success"
}
},
{
"key": "_MACHINE_ID",
"value": {
"stringValue": "5fca68f59b9583a46efa7b9f6697ef74"
}
},
{
"key": "_SELINUX_CONTEXT",
"value": {
"stringValue": "unconfinedn"
}
},
{
"key": "_SYSTEMD_SLICE",
"value": {
"stringValue": "-.slice"
}
},
{
"key": "_UID",
"value": {
"stringValue": "0"
}
},
{
"key": "TID",
"value": {
"stringValue": "1"
}
},
{
"key": "MESSAGE_ID",
"value": {
"stringValue": "7ad2d189f7e94e70a38c781354912448"
}
},
{
"key": "_TRANSPORT",
"value": {
"stringValue": "journal"
}
},
{
"key": "SYSLOG_FACILITY",
"value": {
"stringValue": "3"
}
},
{
"key": "_CAP_EFFECTIVE",
"value": {
"stringValue": "1ffffffffff"
}
},
{
"key": "_CMDLINE",
"value": {
"stringValue": "/lib/systemd/systemd autoinstall --system --deserialize 41"
}
},
{
"key": "SYSLOG_IDENTIFIER",
"value": {
"stringValue": "systemd"
}
},
{
"key": "__MONOTONIC_TIMESTAMP",
"value": {
"stringValue": "598265685166"
}
},
{
"key": "_BOOT_ID",
"value": {
"stringValue": "f0d1b58e375844c3961c527ffc365e6c"
}
},
{
"key": "_SOURCE_REALTIME_TIMESTAMP",
"value": {
"stringValue": "1721831731241074"
}
},
{
"key": "__CURSOR",
"value": {
"stringValue": "s=92ed14a0f4d04f8f9b315bb73d09e814;i=20f1a;b=f0d1b58e375844c3961c527ffc365e6c;m=8b4b69e4ae;t=61dff30b420d6;x=d6baded09f1b919b"
}
},
{
"key": "_EXE",
"value": {
"stringValue": "/usr/lib/systemd/systemd"
}
},
{
"key": "_PID",
"value": {
"stringValue": "1"
}
},
{
"key": "_SYSTEMD_CGROUP",
"value": {
"stringValue": "/init.scope"
}
},
{
"key": "PRIORITY",
"value": {
"stringValue": "6"
}
},
{
"key": "_SYSTEMD_UNIT",
"value": {
"stringValue": "init.scope"
}
},
{
"key": "_GID",
"value": {
"stringValue": "0"
}
},
{
"key": "INVOCATION_ID",
"value": {
"stringValue": "231cd2139b2f4664b755d43b4690aef0"
}
},
{
"key": "_HOSTNAME",
"value": {
"stringValue": "hostname-dev"
}
},
{
"key": "_COMM",
"value": {
"stringValue": "systemd"
}
},
{
"key": "CODE_LINE",
"value": {
"stringValue": "5553"
}
},
{
"key": "MESSAGE",
"value": {
"stringValue": "otelcol-contrib.service: Deactivated successfully."
}
},
{
"key": "CODE_FILE",
"value": {
"stringValue": "src/core/unit.c"
}
}
]
}
}
"traceId": "",
"spanId": ""
}
]
}
]
}
]
}
These log lines turn up in a Telegraph Loki dashboard correctly but each field is prepended with the “body” string due to journald field key/value pairs being nested under “body” outer element in the json log.
Is there a way to cause the fields to not be nested under the body element to render the log lines in Grafana correctly and for field names to not become prepended?