Table of Contents
Distributed Tracing with Spring Cloud Sleuth & Zipkin in Microservices
What have we learned so far,
PART 1 – MICROSERVICES INTRODUCTION – In this tutorial, we discussed what microservices architecture is and how its different from monolithic architecture.
 PART 2 – SCENARIO TO DEVELOP – In this tutorial, we discussed the scenario to develop.
PART 3 – FEIGN CLIENTÂ – In this tutorial, we discussed how feign client simplifies the rest client consumption.
PART 4 – RIBBON CLIENT – In this tutorial, we discussed how ribbon client handles the client side load balancing.
PART 5 – EUREKA NAMING SERVER – In this tutorial, we discussed how Eureka Naming Server is used to dynamically register the services at one place.
PART 6 – ZUUL GATEWAY – In this tutorial, we discussed how Zuul gateway acts as a single entry point to our application.
PART 7 – DISTRIBUTED TRACING WITH SPRING CLOUD SLEUTHÂ –Â In this tutorial, we discussed how Spring sleuth used to generate logs with trace and span ids.
What is Zipkin?
How to log the distributed logs at one place in microservices?
Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in microservice architectures. It manages both the collection and lookup of this data. Zipkin’s design is based on the Google Dapper paper.
Applications are instrumented to report timing data to Zipkin. The Zipkin UI also presents a Dependency diagram showing how many traced requests went through each application. If you are troubleshooting latency problems or errors, you can filter or sort all traces based on the application, length of trace, annotation, or timestamp. Once you select a trace, you can see the percentage of the total trace time each span takes which allows you to identify the problem application.
Till now we have configured sleuth which was giving the trace id to find out the logs from different applications. But the problem with sleuth is its distributed and it becomes very difficult to check all log files one by one to check the logs. Zipkin will solve this problem by giving the central access to all the distributed logs. Lets see how we can implement it.
1. Download the zipkin server from Java section :
https://zipkin.io/pages/quickstart.html
2. After downloading the jar file fire below command to start the zipkin server
java -jar zipkin.jar
This will start the zipkin server on http://localhost:9411
Please follow below url to setup the zipkin server.
Setup Zipkin Server
3. Add below entry in pom file for account-service &customer-service projects
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
4. Add below entry in application.properties file for account-service & customer-service projects
spring.zipkin.base-url=http://localhost:9411/ spring.sleuth.sampler.probability=1
5. Zipkin server internally uses jms to recieve the logs from all the running applications. Please follow Setting up RabbitMQ url to install and start the RabbitMQ server.
6. Now hit the below URL :
http://localhost:8100/accounts/1
7. Open zipkin with http://localhost:9411.
Now it will show the accounts request and its internal rest calls and their logs on same console.
Select the service for which we want to get more information and it will show all the internal rest calls with response time.
Lets see how Zipkin maintains the distributed logs. Every service sends the log with traceId to the RabbitMQ(JMS) server. Zipkin keeps observing thee logs and shows them on dashboard,
Source Code
Download source code of microservice with spring cloud from below git repository :
Lets go to our next tutorial where we will discuss
Part 9 – Fault Tolerance With Hystrix
In this tutorial we will understand below topics
– What is Hystrix?
– How to handle fault tolerance in microservices?
– How to implement the Hystrix in microservices?
PART 9 – MICROSERVICES WITH SPRING CLOUD : FAULT TOLERANCE WITH HYSTRIX
After much frustration and struggling with an old tutorial, I found yours. I'm new to Zipkin and did not realize that Spring deprecated Zipkin UI and Zipkin server from Spring Boot. Now it works. Thank you!
Even I struggled a lot for the Zipkin dependency. I am glad that you found it useful.
Thank you for your valuable input.
Cheers,
Saurabh Oza
Hi Saurabh,
Thank you for your tutorial.
I've been implementing your suggestions and found that Zipkin is working even without RabbitMQ being running. Even if it was, I see no configuration to fetch the log information from RabbitMQ. Can you please clarify me? Tks
Hello Rodrigo, Thanks for writing this to me. Are you able to see the distributed logs from all micro services in Zipkin Server?
Hi Sarurabah, Sorru for my late reply.
Yes, I see the calls, times and IDs. Basic log information. Unless if the actual log is expected.
Examples:
https://snag.gy/p0jC8f.jpg
https://snag.gy/5ou7Hg.jpg
hey i am using kafka as my sender but when and im running my kafka server and zipkin server as well and but when i see the zipkin dashboard im not getting any messages
but when i am making spring.zipkin.sender.type:web then i can see the traces
but the topic of zipkin got created and i can see my logs are being logged but zipkin is not able to consume through kafka
Do you thinking i made any mistake
my dependencies are
org.springframework.cloud
spring-cloud-starter-sleuth
org.springframework.cloud
spring-cloud-starter-zipkin
org.springframework.kafka
spring-kafka
using spring cloud Greenwich.SR2
spring boot version of
2.1.7.RELEASE
application.properties are
spring.sleuth.sampler.probability=1
spring.zipkin.baseUrl=http://localhost:9411
spring.zipkin.sender.type:kafka
sorry for the typo it is spring.zipkin.sender.type= kafka
https://stackoverflow.com/questions/57892994/traces-are-not-being-shown-in-zipkin-when-sender-type-is-kafka
Error: [$controller:ctrlreg] in AngularJS Fix.