Hi,

I have the same problem as described here, https://stackoverflow.com/questions/75214884/all-traces-lost-after-migration-to-springboot-3.

Can you please help me to find a solution?

Comment From: wilkinsona

@MarcelEdmundFranke We prefer not to discuss the same problem in multiple places so I'm going to close this one in favour of the existing question on Stack Overflow. https://github.com/spring-cloud/spring-cloud-stream/issues/2647 may also be of interest as it appears to be in a related area. I've also asked the Spring Cloud team to take a look as they're better-placed to help here.

Comment From: keilw

@wilkinsona There is also a Stack Overflow https://stackoverflow.com/questions/75473467/trace-id-propagation-in-spring-boot-3-with-spring-cloud-streams-and-webflux explaining such problem totally unrelated to Kafka. IMO this is not a duplicate and the focus on Kafka too narrow.

Comment From: wilkinsona

@keilw that SO question is using Spring Cloud Stream's Kafka Binder. Why do you believe it's "totally unrelated to Kafka"?

Comment From: keilw

@wilkinsona Because in a customer project about migrating from Sleuth to Micrometer (SB3) we get exactly the same warnings like:

2023-02-16T17:06:22.166  WARN [63ee385de15f1061dea076eb06b0d1e0,39a60588a695a702] 220348 --- [container-0-C-1] i.m.o.c.ObservationThreadLocalAccessor   : Scope from ObservationThreadLocalAccessor [null] is not the same as the one from ObservationRegistry [io.micrometer.observation.SimpleObservation$SimpleScope@523fe6a9]. You must have created additional scopes and forgotten to close them. Will close both of them
2023-02-16T17:06:22.170  WARN [63ee385de15f1061dea076eb06b0d1e0,de5d233d531b10f7] 220348 --- [container-0-C-1] i.m.o.c.ObservationThreadLocalAccessor   : Scope from ObservationThreadLocalAccessor [null] is not the same as the one from ObservationRegistry [io.micrometer.observation.SimpleObservation$SimpleScope@545339d8]. You must have created additional scopes and forgotten to close them. Will close both of them
2023-02-16T17:06:22.187  WARN [63ee385de15f1061dea076eb06b0d1e0,de5d233d531b10f7] 220348 --- [container-0-C-1] i.m.o.c.ObservationThreadLocalAccessor   : Scope from ObservationThreadLocalAccessor [null] is not the same as the one from ObservationRegistry [io.micrometer.observation.SimpleObservation$SimpleScope@44400bcc]. You must have created additional scopes and forgotten to close them. Will close both of them

but without any use of - implementation 'org.springframework.cloud:spring-cloud-stream' - implementation 'org.springframework.cloud:spring-cloud-starter-stream-kafka'

The remaining dependencies are identical, so the problem calling WebClient like

webClient.get()
                        .uri("http://localhost:8080/test")
                        .exchangeToMono(httpResponse -> httpResponse.bodyToMono(String.class)
                                .map(httpBody -> MessageBuilder.withPayload(httpBody)
                                        .copyHeaders(httpResponse.headers().asHttpHeaders())
                                        .build())

or similar is unrelated to Kafka.

Comment From: wilkinsona

I'm not sure how we were supposed to infer that from a link to a question about Spring Cloud Stream Kafka.

I would recommend asking a question of your own on Stack Overflow with a minimal, reproducible example. Unfortunately, three lines of log output and 6 lines of code are not enough to diagnose the problem.

Comment From: keilw

I don't think we can share something on SO, but I'll tell them, that there is currently no solution, at least not in WebFlux.

Comment From: wilkinsona

I'm not sure why you believe there's no solution. I certainly haven't said that's the case. All I have said is that you haven't provided enough information for us to know what the problem is. Without a precise definition of the problem, it's impossible to say if there's a solution.

You don't need to share your customer's code on Stack Overflow. The ideal is a standalone example that contains just enough to reproduce the problem and nothing more.

Comment From: keilw

The whole migration is time-boxed and we are already at the end of that box, therefore I have to see if I'm granted more time to reproduce this particular issue, otherwise it'll be up to someone else.

Comment From: keilw

I actually found a different solution to our problem here: https://betterprogramming.pub/tracing-in-spring-boot-3-webflux-d432d0c78d3e The key was to use the pre-injected WebClient.Builder in the constructor. They apply a somewhat similar approach via a @Bean, but maybe that does not work that well either. I may mention a word or two in that SO article, but that's all I can do.

Comment From: wilkinsona

Yes, you must use the auto-configured WebClient.Builder to create WebClient instances if you want the requests to be observed. This is described in the documentation.