RousselTMLEARNING

Observability

OpenTelemetry traces in Elasticsearch and Kibana APM

Instrument applications with OpenTelemetry or EDOT SDKs, send traces to Elasticsearch, get Kibana APM views, sample, and link traces and logs.

1. Instrumenting #

OTel or EDOT SDKs.

Automatic instrumentation #

Three instrumented services, EDOT Collector, Elasticsearch, Kibana APM.
# Java : agent EDOT (ou agent OpenTelemetry Java)
export OTEL_SERVICE_NAME=checkout
export OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=prod,service.version=1.4.2
java -javaagent:elastic-otel-javaagent.jar -jar checkout.jar
Good to know: EDOT SDKs are distributions of OpenTelemetry SDKs with defaults tuned for Elastic; standard OpenTelemetry SDKs work too.

2. In Kibana #

Services, transactions, map.

APM views #

With the EDOT Collector (Elastic's APM connector and processor), Kibana shows each service's latency, throughput, error rate, dependencies and the service map. A trace opens as a waterfall with its spans.

FROM traces-*.otel-*
| WHERE resource.attributes.service.name == "checkout" AND status.code == "Error"
| KEEP @timestamp, trace_id, name, duration
| SORT @timestamp DESC | LIMIT 20

3. Sampling and correlating #

Keeping what matters.

Tail sampling #

processors:
  tail_sampling:
    decision_wait: 10s
    policies:
      - { name: erreurs, type: status_code, status_code: { status_codes: [ERROR] } }
      - { name: lentes, type: latency, latency: { threshold_ms: 800 } }
      - { name: echantillon, type: probabilistic, probabilistic: { sampling_percentage: 10 } }
Common mistake: Sampling in the SDKs AND in the Collector unknowingly: you keep 10% of 10%, and APM metrics computed on the remaining spans become wrong. Compute APM metrics before sampling.

Linking logs and traces #

When the SDK injects trace_id and span_id into logs (OTel appenders for log4j, logback, Python logging), Kibana jumps from a trace to its logs and back.

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,…

Ingesting OpenTelemetry logs into Elasticsearch

Collect and structure logs with the OpenTelemetry Collector (filelog receiver, operators, transform processor…

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!