Video in progress

What is OpenTelemetry, and how can you connect it to a Java application?

OpenTelemetry is a vendor-neutral standard for traces, metrics and logs: an API, an SDK, automatic instrumentation and the OTLP protocol. In Java the fastest way is to attach an agent with -javaagent; in Spring Boot 3 there are also Micrometer Tracing's OTel bridge and the OTel Spring Boot starter.

📖 Answer

Before, every vendor had its own agent and format: Zipkin, Jaeger, Datadog. OpenTelemetry unified them. The application sends in OTLP format, and where it goes is a matter of configuration.

With the agent (no code changes):

java -javaagent:/opt/opentelemetry-javaagent.jar \
     -Dotel.service.name=order-service \
     -Dotel.exporter.otlp.endpoint=http://otel-collector:4318 \
     -jar app.jar

The agent modifies bytecode at load time and automatically instruments many libraries such as Spring MVC, JDBC, Kafka, HTTP clients and Redis. The trace context is passed between services on its own.

In between there is usually an OpenTelemetry Collector. It receives the data, does sampling or filtering, and sends it to Tempo, Jaeger, Prometheus or a commercial system. The application knows only the Collector.

The agent has a cost: startup is a bit slower, it uses a bit more memory, and it is a black box, since you learn what is instrumented only from the configuration.

In Spring Boot 3 the alternative is micrometer-tracing-bridge-otel and opentelemetry-exporter-otlp. Here the instrumentation goes through Spring's Observation API and no agent is needed, but coverage is limited to the libraries Spring knows about.

To open a span by hand in your own code, you use the Tracer from the OTel API or Observation from Micrometer.