Understanding Distributed Tracing with Spring Cloud Sleuth and Zipkin
This article explains the principles and practical steps for implementing distributed tracing in microservice architectures using Spring Cloud Sleuth and Zipkin, covering why tracing is needed, core concepts like Span and Trace, Maven integration, Docker deployment, Zipkin UI usage, and performance analysis.
Introduction: The article explains the principles and practice of distributed tracing in microservice architectures, focusing on integrating Spring Cloud Sleuth and Zipkin into the open‑source PassJava project.
It describes why tracing is needed when services are split and logic is complex, and introduces core concepts such as Span, Trace, Annotation, and how a Trace ID links spans together.
Implementation steps include adding Spring Cloud dependencies and Sleuth starter via Maven, configuring logging, and running the relevant microservices (gateway, question, admin). Example Maven snippets:
<dependencyManagement>
<dependencies>
<!-- Spring Cloud dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>Configuration properties for Sleuth and Zipkin are also provided:
# zipkin server address
spring.zipkin.base-url=http://192.168.56.10:9411/
spring.zipkin.discovery-client-enabled=false
spring.zipkin.sender.type=web
spring.sleuth.sampler.probability=1The article then covers Zipkin’s architecture (Collection, Storage, API, UI) and the tracing flow, followed by Docker commands to start Zipkin and optionally use Elasticsearch for storage:
docker run -d -p 9411:9411 openzipkin/zipkin docker run --env STORAGE_TYPE=elasticsearch --env ES_HOSTS=192.168.56.10:9200 openzipkin/zipkin-dependenciesTesting steps show how to invoke APIs, view logs, and interpret Zipkin UI results, including performance metrics such as request transmission time, server processing time, and total latency.
Conclusion: The article summarizes the core tracing concepts, demonstrates Sleuth + Zipkin integration in a real project, and provides links to the open‑source repository for further exploration.
Wukong Talks Architecture
Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.