Spring Cloud Sleuth & Zipkin - SirajChaudhary/comprehensive-example-on-microservices-using-spring-boot-with-spring-cloud GitHub Wiki
Spring Cloud Sleuth is used to generate and attach the trace id, span id to the logs so that these can then be used by tools like Zipkin and ELK for storage and analysis
Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in service architectures. If you have a trace ID in a log file, you can jump directly to it. Otherwise, you can query based on attributes such as service, operation name, tags and duration. Some interesting data will be summarized for you, such as the percentage of time spent in a service, and whether or not operations failed.
Step1: Add Sleuth & Zipkin dependencies in pom.xml in every microservice, and api gateway
<!-- spring cloud starter sleuth -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<!-- spring cloud starter zipkin -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
Step2: Configure Sleuth properties in application.yaml in api gateway
spring:
# SLEUTH PROPERTY
sleuth:
reactor:
instrumentation-type: decorate-on-each
Step3: Configure Zipkin properties in application.yaml in every microservice
spring:
# ZIPKIN SERVER
zipkin:
base-url: 'http://localhost:9411'
Step4: Download & start the zipkin server with command java -jar zipkin-server-2.23.4-exec.jar
Step5: Run zipkin server and trace any sleuth request
http://localhost:9411