10. Distributed Tracing 3: Map Zipkin Server with Microservices and Monitor in Zipkin Server

If we are using Spring Boot 2.7.x and Spring Cloud 2021.0.x then we can use Spring Cloud Sleuth dependency. Spring Cloud Sleuth library is deprecated in the latest version of Spring Cloud 2022.0.0. And alternative added Micrometer-related dependency with the updated Spring Boot and Spring Cloud version.
Distributed Microservice

We are using Spring Boot 3.3.4 and Spring Cloud 2023.0.3 therefore will use micrometer-related dependency.

Development Steps
  1. Add required dependency in microservices
  2. Configurations in application.properties file
  3. Send a request from Client (Postman)
  4. Monitor explain in Zipkin UI including Dependency.
Step 1: Add Dependency: Add the below dependency in all microservices except Service Registry and Config Server.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-micrometer</artifactId>
</dependency>
Dependency
These dependencies are required to add in all microservices to trace as chain.

  • micrometer-observation dependency will allow us to collect and report metrics from our application to Zipkin.
  • micrometer-tracing-bridge-brave dependency will allow us to trace our spring boot application.
  • zipkin-reporter-brave dependency allows us to send traces that we collect to Zipkin.
  • feign-micrometer dependency was added because I am using feign in my microservices to call other APIs. This dependency will configure the micrometer to work with feign.
Step 2: Configure the configuration file: Add the below configuration in application.properties file.
management.tracing.enabled=true
management.zipkin.tracing.endpoint=http://localhost:9411/api/v2/spans
management.tracing.sampling.probability=1.0 
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
logging.level.org.springframework.web=DEBUG
Configurations
These configurations are required to add on application.properties file of each microservices


Step 3: Test by Send a Request: Once the above setup is complete, we're ready to test our application. Start by running all the microservices, then use a client tool like Postman to send a request and verify everything works as expected.
Request send from Postman
Request send from Postman


Step 4: Monitor the Hierarchy of the API request in Zipkin Server:
 
Open the Zipkin UI in a browser and add the service name to trace. Typically we call all microservices through API-Gateway so we are going to add the API-Gateway service name (api-gateway) here.
Zipkin UI

Zipkin UI
See the Hierarchy of API calling and status

Zipkin UI
Chain of microservices that call internally from API-Gateway for a request

This is how we can trace and monitor the distributed microservices.

Post a Comment

0 Comments