Distributed Tracing in Spring Boot with Zipkin and Sleuth
Problem
In microservices, tracing requests across services is hard without context propagation.
Solution: Sleuth + Zipkin
- Sleuth adds trace IDs to logs
- Zipkin stores and visualizes traces
Add Dependencies
xml<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId></dependency>
Sample Trace Log
log[TraceId: 45df... SpanId: 13ff...] Received request at /order/checkout
Run Zipkin
bashdocker run -d -p 9411:9411 openzipkin/zipkin
Enable in application.yml
yamlspring:zipkin:base-url: http://localhost:9411sleuth:sampler:probability: 1.0
Zipkin UI
TL;DR
With 2 lines of config, you can trace requests across services and monitor latency bottlenecks.