Module 6 · Reliability and infrastructureLesson 63 of 886 minIntermediate
OpenTelemetry
OpenTelemetry is a vendor-neutral standard for producing traces, metrics and logs, so you instrument your code once and send the data anywhere.
Try it
Follow one request and watch each service report its own span with the same trace id. Then swap the tracing backend and notice nothing in the services changes.
Every monitoring vendor used to have its own agent and SDK. Switching meant re-instrumenting every service. OpenTelemetry (OTel), a project of the Cloud Native Computing Foundation, fixes that with one standard.
The pieces
- API and SDK: libraries for each language to create spans, record metrics and emit logs.
- Auto-instrumentation: plug-ins for common frameworks (HTTP servers, database drivers, gRPC, Kafka clients) that create spans without code changes.
- Context propagation: the trace id and span id travel with every request in a standard
traceparentheader, so a trace can follow a request across services written in different languages. - OTLP: the standard protocol for sending the data.
- Collector: a separate process that receives telemetry, processes it, and exports it.
The Collector
The Collector is where the flexibility lives:
- Receivers: accept OTLP, Prometheus, Jaeger, Zipkin and more.
- Processors: batch, filter, add labels, drop sensitive fields, and sample traces (for example, keep every error and 5% of the rest).
- Exporters: send to Jaeger, Tempo, Prometheus, Loki, Datadog, Honeycomb, or several at once.
Services just send to the nearest collector. Changing where data goes is a collector config change.
Getting started
- Add the OTel SDK and auto-instrumentation to each service.
- Set the service name and the collector address with environment variables.
- Run a collector next to your services (as a sidecar or one per node).
- Add a few manual spans around important business steps.
- Put the trace id in your logs so logs and traces link up.