1. The OTel log model #
Body, severity, attributes, context.
Fields #
| OTel field | Stored in Elasticsearch (otel mode) |
|---|---|
| Body | body.text (body.structured) |
| SeverityText / SeverityNumber | severity_text / severity_number |
| Attributes | attributes.* |
| Resource | resource.attributes.* (service.name, host.name, k8s.pod.name) |
| TraceId / SpanId | trace_id / span_id: direct link to the trace |
2. Collecting files #
The filelog receiver.
Configuration #
receivers:
filelog:
include: [/var/log/monapp/*.log]
start_at: end
operators:
- type: regex_parser
regex: '^(?P<ts>\S+) (?P<level>[A-Z]+) (?P<msg>.*)$'
timestamp: { parse_from: attributes.ts, layout_type: gotime, layout: '2006-01-02T15:04:05Z07:00' }
severity: { parse_from: attributes.level }
- type: move
from: attributes.msg
to: body
processors:
resource:
attributes:
- { key: service.name, value: monapp, action: upsert }
service:
pipelines:
logs: { receivers: [filelog], processors: [resource, batch], exporters: [elasticsearch] }Good practice: Always set service.name: it is the key linking a service's logs, traces and metrics in Kibana.Kubernetes #
On Kubernetes, the Collector as a DaemonSet reads /var/log/pods; the k8sattributes processor adds namespace, pod, deployment and labels, essential for filtering.
3. Querying and controlling volume #
ES|QL and filtering.
Queries #
FROM logs-*.otel-*
| WHERE severity_text == "ERROR" AND @timestamp > NOW() - 1 hour
| STATS erreurs = COUNT(*) BY resource.attributes.service.name
| SORT erreurs DESCFiltering at the source #
processors:
filter/debug:
error_mode: ignore
logs:
log_record:
- severity_number < SEVERITY_NUMBER_INFOCommon mistake: Shipping debug logs from all of production: volume, hence storage cost, explodes. Filter in the Collector or lower the level in the application.
