-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Servlet and Webflux Tracing are Inconsistent in 3.0 #33495
Comments
Thanks for the details report @braunsonm I think the logging section of this issue is a duplicate of #33372, see the discussion there. We're aware that the situation is different from what Sleuth did, but there are many things to consider, especially performance. See #33372 (comment) and reactor/reactor-core#3149. As for the Traces part, I think that this is due to two things:
As a first step @braunsonm, could you try creating the following bean and see how things behave in your sample application? This would replicate the fix to come with #33444. @Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public ServerHttpObservationFilter webfluxObservationFilter(ObservationRegistry registry) {
return new ServerHttpObservationFilter(registry);
} |
@bclozel Adding the I haven't had much luck getting the trace and span to appear in the logs like discussed at #33372 and I share the concerns that this would require invasive code changes in our codebases. The solutions provided are able to add context around specific sections of the reactor pipeline but it does not solve the areas I posted above which come from Spring itself, like the logging that occurs when going through the security filter chain, I would expect those to log with the trace ID not only my own logging. |
@bclozel I will try out the sample with Spring Security looking up the parent observation and report back. |
I have exactly the same issue with webflux applications. |
@jzheaux
I tested locally these fixes and all work fine. |
Just to add here... The issue of "not connected traces" can be easily reproduced with a simple Spring Boot / Spring Security application (as shown in #33719). Looking forward to an update and/or fix. |
Thanks for the analysis @belovaf ! |
We use a mix of Servlet and Webflux spring applications. In Spring Boot 3.0 there are differences in how traces are logged and how they are actually recorded on the tracing backend. The logging differences makes it especially difficult to use tools like Grafana and associate trace IDs from Loki since the position of that trace ID seems to move depending on the app type.
I have created a simple sample to reproduce this issue here: https://github.com/braunsonm/spring-inconsistency-sample. In this sample the two applications are identical except one is servlet and the other is webflux. The sample endpoint uses a
RestTemplate
andWebClient
respectively to call https://google.com to generate a simple external source in our traces. This was generated using https://start.spring.io on Spring Boot 3.0I'll go through the differences now:
Logging
In Servlet, you must use
logging.pattern.level
as described in the docs to include the trace and span IDs in your logs. I am using%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
as recommended from the docs. This creates a log like so:However in Webflux, you are unable to get your trace and span IDs even with the recommended setting. You get a log line like so:
Notice how neither the trace nor the span are set in the log line. However it still does upload the span to the tracing backend.
Traces
The trace that is uploaded in Servlet looks how you would expect, a single trace with multiple spans.
In Webflux, multiple traces are submitted for the same request, when only separate spans should be created. This makes the correlation unusable as you can't tell which trace for the security filters is actually part of the request you are looking for.
(This is just 1 REST call)
The text was updated successfully, but these errors were encountered: