How to trace HTTP requests in Spring Boot 3 with Micrometer & Zipkin

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.

enter image description here

So I have some questions about it:

  1. At first, I never perform any requests, why there are so many request on Zipkin dashboard?
  2. I use Postman to perform three requests (1 from order-service, 2 from product-service), why it only show the requests from order-service like this enter image description here
  3. 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.

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:

enter image description here

Upvotes: 3

Views: 8198

Answers (3)

Frode
Frode

Reputation: 11

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

Upvotes: 1

Eston Karumbi
Eston Karumbi

Reputation: 66

Had a similar issue, adding this helped in my case: management.zipkin.tracing.enabled=true

Upvotes: 0

First, I try to check management.tracing.sampling.probability=1.0, and it raise a error:

Cannot resolve configuration property 'management.tracing.sampling.probability' 

I really don't understand why it like that, after that I found the different, there are 2 denpendencie, they look pretty similar:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
        </dependency>

        ...................
        ...................
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

I try to reach out the spring docs: actuator.micrometer-tracing.tracer-implementations and I realize the dependency I actually need is spring-boot-starter-actuator

I insert three new dependencies from docs:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-otel</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-zipkin</artifactId>
        </dependency>

To summary, we will use these dependencies for tracing http request with Micrometer & Zipkin.

  • spring-boot-starter-actuator
  • micrometer-tracing-bridge-otel
  • opentelemetry-exporter-zipkin

Upvotes: 0

Related Questions