Distributed Tracing in Spring Boot using OpenTelemetry + Jaeger (2025 Guide)
This guide helps you understand:
✅ What is distributed tracing
✅ How to enable OpenTelemetry in Spring Boot
✅ How Jaeger receives spans
✅ What is the difference between OTEL vs Prometheus
✅ Complete ready-to-run example with Docker Compose
✅ Architecture diagrams
✅ README for your project
1. What is Distributed Tracing?
Modern microservices often involve multiple services communicating with each other:
Debugging such systems with only logs is extremely difficult.
Distributed Tracing solves this by:
✔ Tracking a request end-to-end
✔ Showing how long each service took
✔ Identifying bottlenecks
✔ Detecting where a failure occurs
OpenTelemetry (OTEL) is the standard for collecting such traces.
2. What is OpenTelemetry (OTEL)?
OpenTelemetry is an open-source CNCF standard for:
-
Traces
-
Metrics
-
Logs
In your Spring Boot app, OTEL:
-
Creates spans
-
Stores them briefly in memory
-
Exports them through OTLP protocol
-
Sends to a backend like Jaeger, Tempo, Zipkin, etc.
✔ OTEL uses a push model
This means:
Your application sends data OUT to Jaeger, like this:
3. What is Jaeger?
Jaeger is an open-source distributed tracing system.
In local mode (all-in-one):
-
Collector
-
Query
-
UI
-
Storage
are all in one container.
Jaeger stores data:
-
In memory (in local mode)
-
Elastic / Cassandra / ClickHouse / etc. (in production)
4. Architecture Diagram (Spring Boot → OTEL → Jaeger)
5. How Does OTEL Export Data? (Important)
👉 OTEL does not store long-term data
👉 OTEL only batches spans in memory for milliseconds
👉 OTEL pushes spans to Jaeger via OTLP
There is no polling.
✔ Jaeger never calls your app
✔ Your app always pushes the data
6. What is Prometheus?
Prometheus is used for:
-
Metrics (CPU, memory, request_count, latency, etc.)
-
Alerting
-
Time-series storage
Prometheus follows a pull model:
✔ Prometheus calls your Spring Boot endpoint
✔ Your app does NOT push data
✔ Prometheus stores metrics on disk
7. OTEL vs Prometheus (VERY IMPORTANT)
| Feature | OpenTelemetry | Prometheus |
|---|---|---|
| Purpose | Tracing (request flow) | Metrics (performance) |
| Data Type | Spans, traces, logs | Time-series metrics |
| Collection Model | Push (App → Jaeger) | Pull (Prometheus → App) |
| How It Works | OTEL sends trace data instantly | Prometheus periodically scrapes |
| What It Shows | End-to-end request timing | CPU, memory, errors, latency |
| Storage | Jaeger (memory/DB) | Prometheus TSDB |
| UI | Jaeger UI | Grafana |
| Ideal Use | Microservice debugging | Monitoring & alerting |
✔ Both used together in production
You use:
➡ OTEL + Jaeger for tracing
➡ Prometheus + Grafana for metrics
8. Spring Boot Example (Tracing /hello endpoint)
Your controller:
Every request generates a trace visible in Jaeger.
9. Docker Compose — Spring Boot + Jaeger
10. Source code
https://github.com/kkvinodkumaran/springboot-tracing-demo-complete
No comments:
Post a Comment