Cloud Native 19 min read

Comprehensive Guide to Spring Cloud Sleuth and Zipkin for Distributed Tracing

This article provides a detailed tutorial on using Spring Cloud Sleuth with Zipkin to monitor and troubleshoot distributed micro‑service calls, covering concepts, configuration, Maven dependencies, YAML settings, controller examples, RabbitMQ integration, logback adjustments, and alternative tracing solutions.

Top Architect
Top Architect
Top Architect
Comprehensive Guide to Spring Cloud Sleuth and Zipkin for Distributed Tracing

In micro‑service architectures a single request often traverses many services, creating complex call chains where latency or errors in any node can cause the whole request to fail; distributed tracing helps identify such problems.

What is Sleuth? Spring Cloud Sleuth adds trace and span IDs to logs and automatically records service‑to‑service calls, sending the data to Zipkin for visualization.

What is Zipkin? Zipkin collects tracing data from Sleuth, stores it, and provides a UI to view spans, traces, and their relationships.

Key terminology includes Span (basic unit of work), Trace (tree of spans), and annotations such as cs, sr, ss, cr that mark client send, server receive, server send, and client receive events.

Practical steps :

Create a Spring Boot project (Java 8) and add spring-boot-dependencies and spring-cloud-starter-sleuth (or spring-cloud-starter-zipkin ) to the pom.xml .

Configure application.yml with server port, application name, and Sleuth sampler settings (probability 1, rate 10).

Implement a simple @RestController that logs a message and returns a string.

Start Zipkin (download zipkin-server-2.23.18-exec.jar and run java -jar zipkin-server-2.23.18-exec.jar ) and access http://localhost:9411/zipkin/ to view traces.

Build two services (ports 8989 and 8990) where the 8989 service calls the 8990 service via OpenFeign; observe shared trace IDs in logs and Zipkin UI.

Introduce an intentional exception in the provider service to see error traces and locate the failing span using the trace ID.

Advanced configuration :

Change Zipkin’s default HTTP sender to RabbitMQ by setting spring.zipkin.sender.type=rabbit and providing RabbitMQ connection details.

Run Zipkin with RabbitMQ support: java -jar zipkin-server-2.23.18-exec.jar --RABBIT_ADDRESSES=127.0.0.1:5672 --RABBIT_USER=guest --RABBIT_PASSWORD=guest or via Docker.

Adjust logback patterns to include Sleuth’s LOG_DATEFORMAT_PATTERN so trace IDs appear in console and file logs.

Persistence options for Zipkin include MySQL and Elasticsearch; the article shows the MySQL command line to start Zipkin with --STORAGE_TYPE=mysql and the required SQL schema.

Other tracing tools mentioned are CAT, SkyWalking, and Pinpoint, each offering different features and storage back‑ends.

Overall, the guide walks readers from basic concepts through a complete hands‑on setup, enabling effective distributed tracing for Spring Cloud micro‑services.

MicroservicesloggingSpring BootDistributed TracingRabbitMQZipkinSpring Cloud Sleuth
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.