RousselTMLEARNING

Observability

Ingesting OpenTelemetry logs into Elasticsearch

Collect and structure logs with the OpenTelemetry Collector (filelog receiver, operators, transform processor, k8sattributes), ship them to Elasticsearch and query them with ES|QL.

1. The OTel log model #

Body, severity, attributes, context.

Fields #

OTel fieldStored in Elasticsearch (otel mode)
Bodybody.text (body.structured)
SeverityText / SeverityNumberseverity_text / severity_number
Attributesattributes.*
Resourceresource.attributes.* (service.name, host.name, k8s.pod.name)
TraceId / SpanIdtrace_id / span_id: direct link to the trace
Receiver, parsing, enrichment, Elasticsearch.

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 DESC

Filtering at the source #

processors:
  filter/debug:
    error_mode: ignore
    logs:
      log_record:
        - severity_number < SEVERITY_NUMBER_INFO
Common mistake: Shipping debug logs from all of production: volume, hence storage cost, explodes. Filter in the Collector or lower the level in the application.

Related articles

Transforms and enrich: summarising and enriching data in Elasticsearch

Build entity-centric indices with pivot and latest transforms, and enrich documents at ingest time with enric…

OpenTelemetry and Elasticsearch: compatibility and architecture

Send OpenTelemetry to Elasticsearch: Collector and elasticsearch exporter, managed OTLP endpoint, APM Server,…

OpenTelemetry traces in Elasticsearch and Kibana APM

Instrument applications with OpenTelemetry or EDOT SDKs, send traces to Elasticsearch, get Kibana APM views, …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!