spring-cloud-sleuth
spring-cloud-sleuth copied to clipboard
NewSpan annotation is breaking Trace hierarchy
Spring Boot 2.7.0-M3 (spring-boot-starter-webflux and spring-boot-starter-graphql)
Spring Cloud Sleuth 3.1.1 (spring-cloud-starter-sleuth and spring-cloud-sleuth-zipkin)
sleuth.reactor.instrumentation-type: decorate_queues
GraphQL Schema is mapped to controller using @QueryMapping which leverages a bean to call an external service with web client, returning Mono<List<?>>
By default the trace produced matches what I would expect:
post /graphql
-> post /my/api
Where -> indicates a child span
When I annotate the bean method with @NewSpan
I expect:
post /graphql
-> myAnnotatedMethod
--> post /my/api
Instead we get two traces:
post /graphql with no children
and
myAnnotatedMethod
-> post/my/api
Example:
@Controller
@SchemaMapping(typeName="Car"_
class MyController {
MyService myService = new MyService();
@QueryMapping
public Mono<List<Car>> getCars() {
return myService.getCars();
}
}
@Service
class MyService {
WebClient webClient;
@NewSpan // Works as expected without this annotation
public Mono<List<Car>> getCars() {
return webClient.post()
.uri(builder -> builder.path("/my/api").build())
// ...
.retrieve()
.bodyToMono(...)
.map(...);
};
}
Can you provide a complete, minimal, verifiable sample that reproduces the problem rather than pasted code? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.
Hi @marcingrzejszczak - I have pushed a sample to https://github.com/dmlogs/sample-sleuth-issue-2150
Comment/uncomment this line to compare the behavior: https://github.com/dmlogs/sample-sleuth-issue-2150/blob/main/src/main/java/com/example/demo/CarService.java#L22
Please upgrade to Micrometer Tracing. Spring Cloud Sleuth is feature complete and out of OSS support.