OpenTelemetry
opentelemetry opentelemetry is the vendor-neutral standard for traces, metrics and logs. spring boot 3.x auto-instruments http, jdbc and kafka — export to
Introduction
OpenTelemetry is the vendor-neutral standard for traces, metrics and logs. Spring Boot 3.x auto-instruments HTTP, JDBC and Kafka — export to Jaeger, Grafana Tempo or Datadog with zero code changes.
Informative example
Manual span + Spring Boot config:
@Servicepublic class OrderService {private final Tracer tracer;public Order create(OrderRequest req) {Span span = tracer.spanBuilder("createOrder").startSpan();try (var scope = span.makeCurrent()) {span.setAttribute("order.sku", req.sku());return repo.save(new Order(req));} finally { span.end(); }}}# application.ymlmanagement.tracing.sampling.probability=1.0management.otlp.tracing.endpoint=http://localhost:4318/v1/traces
Best practices
- Propagate trace context across HTTP and Kafka headers.
- Sample in production (1-10%) — 100% sampling is expensive.
- Correlate traceId with log MDC for unified debugging.
Purpose of this lesson
Master OpenTelemetry so you can apply it confidently in production Java code, technical interviews, and code reviews.
Step-by-step explanation
- Understand the core idea behind OpenTelemetry.
- Walk through the runnable example and tweak it in the playground.
- Apply the pattern in a small Spring Boot or CLI exercise of your own.
- Re-read the common mistakes and interview Q&A to lock the concept in.
Interactive workflow diagram
Identify use case
Recognize when opentelemetry is the right tool for the problem.
Debugging tips
- Read the full stack trace — Java's exception messages name the offending class and line.
- Reproduce in the smallest possible
main()method before fixing in the real app. - Use IntelliJ's debugger breakpoints and 'Evaluate Expression' rather than scattering
System.out.
Optimization strategies
- Profile before optimizing — JFR (Java Flight Recorder) and async-profiler reveal real hotspots.
- Prefer immutable data and stream pipelines over hand-rolled loops when readability matters.
- Reach for the right JDK collection (ArrayList vs LinkedList vs ArrayDeque) before writing custom data structures.
Enterprise example
Grafana's LGTM stack (Loki, Grafana, Tempo, Mimir) ingests OpenTelemetry natively — one SDK, full observability.
Interview questions & answers
Q1Explain OpenTelemetry in one minute.
Q2When would you avoid OpenTelemetry?
Summary
In this lesson you learned OpenTelemetry — the concept, syntax, a runnable example, and the production pitfalls to avoid. Apply it in the playground before moving on.