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.
We are using Spring Boot 3.3.4 and Spring Cloud 2023.0.3 therefore will use micrometer-related dependency.
Development Steps
- Add required dependency in microservices
- Configurations in application.properties file
- Send a request from Client (Postman)
- 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>
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=truemanagement.zipkin.tracing.endpoint=http://localhost:9411/api/v2/spansmanagement.tracing.sampling.probability=1.0logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]logging.level.org.springframework.web=DEBUG
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 |
See the Hierarchy of API calling and status |
Chain of microservices that call internally from API-Gateway for a request |
This is how we can trace and monitor the distributed microservices.
0 Comments