My purpose is to trace every request to my system. I watched 2 video below on Youtube to config Micrometer & Zipkin for tracing.
But, when I access http://localhost:9411/zipkin/
, it worked abnormally and make me confused.
So I have some questions about it:
order-service
, 2 from product-service
), why it only show the requests from order-service
like this
api-gateway service
first, it is not the same as video 1.For Micrometer config, I reference Micrometer and Zipkin: How to Trace HTTP Requests in Spring Boot 3
I insert management.tracing.sampling.probability=1.0
to each application.properties
file and these dependencies below to each pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<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>
This is my architecture system:
Why the spans (Zipkin dashboard) always is 1. Although every requests must go through api-gateway service first, it is not the same as video 1.
This for me was because I was creating a RestTemplate instance myself, which meant Micrometer could not automatically instrument it causing no context to be propagated. Adding the following configuration and autowiring the bean instead of creating a RestTemplate myself fixed it.
@Configuration
public class RestTemplateConfiguration {
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.build();
}
}
This blog post describes the issue in detail: https://medium.com/@TimvanBaarsen/spring-boot-why-you-should-always-use-the-resttemplatebuilder-to-create-a-resttemplate-instance-d5a44ebad9e9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With