Learn Distributed Tracing With Spring Cloud Sleuth and Zipkin

Go Back to Course Outline Project Architectural Overview Join our Group FB Page: FB Gro...

Go Back to Course Outline

Project Architectural Overview

Join our Group
Join my czetsuya tech community site to Get Answers to Questions about programming, home-based work, anything about tech and to connect and share information.


In this architecture, we have several microservices that communicate with each other to perform a single task, such as the get product stock service in the business API. This is a 2 level deep request that pulls and joins data from the catalog and inventory microservice.

This kind of architecture introduces some challenges such as log tracing across multiple microservices with each service running several instances as well as the latency between each request hop. This is where Spring Cloud Sleuth comes in, by adding metadata such as ID in the request header. 

These logs are aggregated using Spring Zipkin which makes debugging easier.

2 Types of ID

  1. Trace ID - It adds a unique ID whenever a new request is initiated plus it contains a set of span IDs. Its value does not change across microservices.
  2. Span ID - It represents a basic unit of work such as fetching a record from a database.

How to add Zipkin to our Projects

  1. Add spring-cloud-starter-zipkin dependency to all the projects that we want to trace.
  2. Add the following properties to the microservies that we want to trace
    1. spring.zipkin.baseUrl
    2. spring.zipkin.discovery-client-enabled=false
    3. spring.sleuth.sampler.probability=100, it means all spans will be sent to Zipkin server

Run the Applications

Run the microservices in this order:
  1. terawarehouse-config-server (node1)
  2. terawarehouse-service-discovery (node1)
  3. terawarehouse-load-balancer (node1)
  4. terawarehouse-catalog (node2)
  5. terawarehouse-inventory (node2)
  6. terawarehouse-business-api (node2)

How to Run Zipkin with Docker

You must have docker installed

>docker run -d -p 9411:9411 openzipkin/zipkin

Trace the Logs

  1. In node2 open the Zipkin URL: :9411
  2. Run the postman collection inside the src/test/resources folder in terawarehouse-catalog project.




spring-microservice 3977350756182412418

Post a Comment Default Comments