Quantcast
Channel: Active questions tagged propagation - Stack Overflow
Viewing all articles
Browse latest Browse all 52

Spring brave creates another traceId with WebClient

$
0
0

I am creating a spring-boot3 service that needs to interact with a spring-boot2 sleuth service.

I configured the spring-boot3 app to propagate B3 trace-ids using WebClient. The problem is that WebClient is creating another trace-id.

This is the endpoint that I execute http://localhost:8080 which in turns calls to http://localhost:9090

@RestController@SpringBootApplicationpublic class MyApplication {  private static final Log logger = LogFactory.getLog(MyApplication.class);  @Autowired WebClient.Builder builder;  @RequestMapping("/")  String home() {    logger.info("Testing sending request to client");    String data = builder        .baseUrl("http://localhost:9090")        .exchangeStrategies(ExchangeStrategies.builder().codecs(c ->            c.defaultCodecs().enableLoggingRequestDetails(true)).build()        )        .build()        .get()        .exchangeToMono(res -> res.bodyToMono(String.class))        .block();    return data;  }}

A Config to use B3 style traces

@Configurationpublic class Config {  @Bean  public Tracing braveTracing() {    return Tracing.newBuilder()        .propagationFactory(            B3Propagation.newFactoryBuilder()                .injectFormat(B3Propagation.Format.MULTI)                .build())        .build();  }}

properties

spring.application.name=demologging.level.org.springframework.web=TRACE#spring.mvc.log-request-details=true#spring.http.log-request-details=truespring.codec.log-request-details=truemanagement.tracing.propagation.type=B3logging.level.org.springframework.web.reactive.function.client.ExchangeFunctions=TRACEmanagement.tracing.enabled = truemanagement.tracing.sampling.probability = 1.0

Dependencies in build.gradle

implementation 'org.springframework.boot:spring-boot-starter-actuator'implementation 'org.springframework.boot:spring-boot-starter-web'implementation 'io.micrometer:micrometer-tracing-bridge-brave'implementation 'org.springframework.boot:spring-boot-starter-webflux'testImplementation 'org.springframework.boot:spring-boot-starter-test'

Finally the logs I got:

2024-04-16T15:10:27.010-04:00 TRACE 34890 --- [demo] [nio-8080-exec-1] [121d49ff22764a67                -121d49ff22764a67] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.example.demo.MyApplication#home()2024-04-16T15:10:27.027-04:00 TRACE 34890 --- [demo] [nio-8080-exec-1] [121d49ff22764a67                -121d49ff22764a67] o.s.web.method.HandlerMethod             : Arguments: []2024-04-16T15:10:27.028-04:00  INFO 34890 --- [demo] [nio-8080-exec-1] [121d49ff22764a67                -121d49ff22764a67] com.example.demo.MyApplication           : Testing sending request to client2024-04-16T15:10:27.138-04:00 TRACE 34890 --- [demo] [nio-8080-exec-1] [121d49ff22764a67                -121d49ff22764a67] o.s.w.r.f.client.ExchangeFunctions       : [2f40d44] HTTP GET http://localhost:9090, headers=[X-B3-TraceId:"8089985fbcccddfa", X-B3-SpanId:"8089985fbcccddfa", X-B3-Sampled:"1"]

The trace-id in the spring-boot3 app is 121d49ff22764a67 and the one that's propagated is 8089985fbcccddfa. What am I missing to propagate the first trace-id 121d49ff22764a67 ?


Viewing all articles
Browse latest Browse all 52

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>