spring-bootmicrometerbravemicrometer-tracing

micrometer tracing brave + rest template / web client


I am trying to propagate traceId from one service to another that is called by rest template / web client

I'd expect that the traceId will be the same but in reality the new one is generated.

service 1:

    @Bean
    public WebClient webClient() {
        return WebClient.create("http://localhost:8080");
    }

simpe call to service-2:

webClient.get().retrieve().bodyToMono(String.class).block();

I have these dependencies in both services:

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-brave</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

I got the same behaviour with rest template. According to documentation the traceparent header should be propagated, but its not. I am using spring boot 3.0.5


Solution

  • As you are builing a WebClient from scratch, no autoconfiguration is taking place. You should change the WebClient bean method and inject a WebClient.Builder.

        @Bean
        public WebClient webClient(WebClient.Builder builder) {
            return builder.baseUrl("....").build();
        }