spring-cloud / spring-cloud-sleuth

Distributed tracing for spring cloud

Home Page:https://spring.io/projects/spring-cloud-sleuth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why doesn't Sleuth enable Scope when create Span for Kafka Streams by default?

lianej opened this issue · comments

Hi team,

My project is based on spring-cloud-stream-kafka 3.1.4 and spring-cloud-sleuth 3.0.4 (and zipkin brave).
When I use Sleuth, while also benefiting from tracing context information from slf4j.MDC such as traceId and spanId, it allows me to track logs more easily.

However, I recently found out that when Sleuth collects information about kafka-streams endpoints, it does not update MDC.
This is because Brave only updates MDC when a span is in scope(brave.context.slf4j.MDCScopeDecorator.MDCContext), and Sleuth does not have corresponding support for spring cloud stream kafka; it directly uses the kafka-streams instrument provided by Brave.
As far as I know, none of the instruments provided by Brave simultaneously enable scope when create/get span.

On the other hand, the web instruments (such as org.springframework.cloud.sleuth.instrument.web.servlet.TracingFilter) provided by Sleuth have scope enabled during processing.

Q:

  1. Is it true that Sleuth does not enable Scope when processing Kafka Streams?
  2. (If the answer to 1 is True) Why is Scope not enabled when processing kafka-streams endpoints, but it is enabled when handling Web requests?
  3. Is opening the scope myself a good practice? (through AOP or other means)

I think this is intentional since you can get multiple messages at that point, which one of them should be chosen for propagating its tracing information?
Also, even if this would be a bug, Sleuth 3.1 reached the end of its OSS support lifetime, you should migrate to the latest Micrometer Tracing (and latest Spring Boot 3.x).