-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Document limitations of Servlet Filter observations #29398
Comments
Hey @jonatan-ivanov From what I understand, this is being logged from an I don't think Framework can do anything about that. |
Yes, it is definitely out of the scope of the Observation. @marcingrzejszczak might have more details, in Sleuth, we fixed it with a |
I guess Tomcat is logging the name of the Servlet. I did discuss the Valve possibility with Marcin, and while it would bring better measurements in general, I don't think it's the right approach for Framework:
Taking a step back, I think the Servlet filter is enough to instrument the application behavior. |
I think having traceId/spanId on error logs is a vital feature. |
I think that the main issue here is that exceptions unhandled by the web framework are not logged by Spring and bubble up to the Servlet container, which chooses to log them at the ERROR level. If Spring web frameworks logged those exceptions, this user experience issue would be solved. Considering a custom valve here would only work for Tomcat and would not address the issues listed in my previous comment.
Note that exceptions handled by Spring MVC are logged by the Framework, not by the container. For example here, using the new Problem Detail support (this would also work for any exception handler in general). @Controller
public class SomeController {
private static final Log logger = LogFactory.getLog(SomeController.class);
@GetMapping("/test")
public String test() {
logger.info("test() is called");
throw new IllegalStateException("the request has an invalid state");
}
@ExceptionHandler(IllegalStateException.class)
ProblemDetail handleIllegalState(IllegalStateException exc) {
ProblemDetail problemDetail = ProblemDetail.forStatus(HttpStatus.BAD_REQUEST);
problemDetail.setTitle("Illegal State");
return problemDetail;
}
}
|
I only used the valve as an example (Tomcat), I'm not saying we should use it or that would be a universal solution. I'm only saying that out of the box this does not work and this is a rather important functionality. I guess the question for me is: can we do anything with this in the 6.0 timeline or in 6.1? I.e.: brainstorming about it with the whole team? If this can't be fixed in 6.0, can we document it? I guess other options should work too, like having a ControllerAdvice or using a custom ObservationHandler. |
I think we need to document this as a known behavior in our web observability support documentation. Since the instrumentation is done at the Servlet filter level, we can't extend the observation outside of this scope. Applications and libraries can write container-specific instrumentation with broader support but this won't be supported at the Spring Framework level. |
This is a workaround for missing log correlation (see details in spring-projects/spring-framework#29398).
Affects: 6.0.0-SNAPSHOT
If micrometer-observation is set-up and if I throw an exception from a controller:
The
ERROR
log entry does not contain the traceID/spanId, see[boot3-sample,,]
(log correlation does not work):I think the issue is either the error logging is not "observed" or it is not "in-Scope".
The text was updated successfully, but these errors were encountered: