Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Cloud Sleuth different trace-ID integrate with Kafka

I'm using Kafka for Asyng calls between microservices, and i'm using Spring Sleuth for logging. The logging is ok, but when there is a message from Microservice1 to Microservice2, the logging's messages have different Trace-ID. Don't they have to have the same trace-Id but a different SpanId? is there any special configuration?

like image 690
AleGallagher Avatar asked Oct 15 '25 15:10

AleGallagher


1 Answers

Message headers by default will not be transported by Spring Cloud Kafka binder, you have to set it via spring.cloud.stream.kafka.binder.headers manually as described in the Spring Cloud Stream Reference Guide. And then check if those tracing related headers been sent properly.

You can set Zipkin headers as following in your application.yml:

spring:
  cloud:
    stream:
      kafka:
        binder:
          headers:
            - X-B3-TraceId
            - X-B3-SpanId
            - X-B3-Sampled
            - X-B3-ParentSpanId
            - X-Span-Name
            - X-Span-Export

Or in your application.properties:

spring.cloud.stream.kafka.binder.headers[0]=X-B3-TraceId
spring.cloud.stream.kafka.binder.headers[1]=X-B3-SpanId
spring.cloud.stream.kafka.binder.headers[2]=B3-Sampled
spring.cloud.stream.kafka.binder.headers[3]=X-B3-ParentSpanId
spring.cloud.stream.kafka.binder.headers[4]=X-Span-Name
spring.cloud.stream.kafka.binder.headers[5]=X-Span-Export

Or in a comma-separated list:

spring.cloud.stream.kafka.binder.headers=X-B3-TraceId,X-B3-SpanId,B3-Sampled,\
    X-B3-ParentSpanId,X-Span-Name,X-Span-Export
like image 114
tan9 Avatar answered Oct 17 '25 09:10

tan9



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!