-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracer.activeSpan() returning null if Spring Cloud Gateway is present #1807
Comments
Please check the documentation https://docs.spring.io/spring-cloud-sleuth/docs/3.0.0-RC1/reference/html/integrations.html#sleuth-http-server-webflux-integration With the latest releases we turn on Lines 234 to 271 in 76ad931
In order to make your code work @SpringBootApplication
public class DemoApplication {
public static void main(final String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public RouterFunction<ServerResponse> helloWorld(final WebClient.Builder builder, org.springframework.cloud.sleuth.Tracer tracing, CurrentTraceContext currentTraceContext)) {
return route(GET("/hello"), request -> Mono.fromCallable(() -> WebFluxSleuthOperators.withSpanInScope(tracing, currentTraceContext, request.exchange(), () -> "Active Span is " + tracer.activeSpan())
.flatMap(result -> ServerResponse.ok().contentType(TEXT_PLAIN).body(fromValue(result))));
}
} The most important part is WebFluxSleuthOperators.withSpanInScope(tracing, currentTraceContext, request.exchange(), () -> "Active Span is " + tracer.activeSpan()) When making such a call, this lambda |
Another option (discouraged) is to set explicitly |
But the weird thing is, my code works perfectly fine until I add Spring Cloud Gateway as a dependency. Merely adding that dependency causes the code to break. If I'm on RC1 and no SCG, my code works just fine. Why is that? |
Thanks for this. I have a couple of questions for clarification.
|
Finally: what's the reason that including SCG forces this property to "manual" by default? Wouldn't it be best to keep the default the same between SCG apps and non-SCG apps for compatibility? |
What
SCG's instrumentation works regardless of the chosen instrumentation type. It reuses the
If you wrap logging in
Cause other instrumentation is broken and SCG works regardless of the chosen instrumentation type. The instrumentation type changes the way your custom code behaves. |
Description
After updating from Release Train 2020.0.0-M4 to 2020.0.0-M6,
Tracer.activeSpan()
is returningnull
if Spring Cloud Gateway is present. Issue is still present in RC1. It's as if OpenTracing isn't configured properly with the latest 2020.0.0 release and Spring Cloud Gateway. My guess is it has to do with #1757 breaking SCG integration?If I revert to M4 or a Hoxton release, it works. If I remove Spring Cloud Gateway, it works (but of course, my routes no longer work).
Sample
I've created a sample project which demonstrates the problem here: https://github.com/blake-bauman/test-spring-cloud-sleuth-gateway
With SCG dependency included, the result is
null
, but remove the dependency and you get an active Span.For reference, the application is:
In our real project, we've also hooked up the trace data to the logging, and the trace data is also missing from the logs with SCG included. Without SCG, it shows up.
The text was updated successfully, but these errors were encountered: