Professional Documents
Culture Documents
Implementing Distributed Tracing With Spring Cloud Sleuth, Zipkin
Implementing Distributed Tracing With Spring Cloud Sleuth, Zipkin
References:
https://howtodoinjava.com/spring-cloud/spring-cloud-zipkin-sleuth-
tutorial/
https://www.baeldung.com/tracing-services-with-zipkin
https://dzone.com/articles/spring-cloud-amp-spring-
bootimplementing-zipkin-se
https://spring.io/blog/2016/02/15/distributed-tracing-with-spring-
cloud-sleuth-and-spring-cloud-zipkin
Now you can click on the AactiveMQ web console link to open the
ActiveMQ dasdboard
https://b-454903b5-4dc9-49d4-a8cf-f9669d8122e8-1.mq.ap-
southeast-2.amazonaws.com:8162
When you see the dashboard screen that mean your ActiveMQ broker
is created successfully.
If you can’t connect to you ActiveMQ dashboard please make sure
that Plublic Accessibility is turning on (yes)
And Secrurity Group already added ports to access from outside.
Zipkin Server
Start zipkin by Docker
docker run -d -p 9411:9411 -e
ACTIVEMQ_URL='failover:(ssl://
b-454903b5-4dc9-49d4-a8cf-f9669d8122e8-1.mq.ap-
southeast-2.amazonaws.com:61617,ssl://
b-454903b5-4dc9-49d4-a8cf-f9669d8122e8-2.mq.ap-
southeast-2.amazonaws.com:61617)' -e
ACTIVEMQ_USERNAME=thanhct -e
ACTIVEMQ_PASSWORD=xxxxx -e
ACTIVEMQ_CONCURRENCY=8 openzipkin/zipkin
If everything is ok now you are running the zipkin server and It’s
connected to ActiveMQ as a consumer.
Now move to browser then type http://localhost:9411 Zipkin’s
dashboard will appear.
Dependences
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-activemq-client</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-spring-beans</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<!-- temporary until sleuth has next zipkin-reporter release -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-bom</artifactId>
<version>2.9.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Now when you run your microservices you can see log as below:
All services you can see are different tracing log compare with after
you’re intergrated Spring Cloud Sleuth.
That’s [service-zuul-
gateway,d976e46e9c6e74df,d976e46e9c6e74df,true] It mean
you’re added sleuth successfully.
service-zuul-gateway: the name of the application that logged the
span.
d976e46e9c6e74df: the id of the latency graph that contains the
span.
d976e46e9c6e74df: the id of a specific operation that took place.
true: whether the log should be exported to zipkin or not.
Important thing:
Configure the percentage of spans exported using
spring.sleuth.sampler.probability: 1.0 (range: 0.1 -> 1.0)
In this solution we set it 1.0 it mean 100% spans will be exported.
this is the time you can run all your microservices(zuul, oAuth2,
eureka, master-common, buyer-master-common) to test your tracing
Use postman or CLI to call you microservices with code below:
curl -X POST \
http://localhost:8888/service-oauth/v1/api/
login/token \
-H 'Accept: application/json, text/plain, */*'
\
-H 'Authorization: basic
Qmh3LUVwcy1KaWVuaWU6c2VjcmV0' \
-H 'Content-Type: application/x-www-form-
urlencoded' \
-H 'Postman-Token: 5c70952f-
c336-4759-8164-82d858db8fb5' \
-H 'cache-control: no-cache' \
-d
'username=V2Applicant&password=test123&client_id
=Bhw-Eps-
Jienie&grant_type=password&company_group_code=00
01'
After API call succeed, we can see the latency statistics at zipkin UI
http://localhost:9411 at service name option choose all service
then click Find Traces button. Then swicth to Try Lens UI to have
more better look and feel. So now you can know where you can do
performance analysis by looking at tracing dat.
You can see overview of request and you can see timing, you can see
the details of request and how long does it take.