We use an ErrorController class to handle some of our error scenarios (including: user requests a non-existent endpoint, user requests an endpoint with an unsupported method, etc). For logging purposes, the methods in our ErrorController need access to the trace ID of the current request.
We are currently on Spring Boot 2.x.x and using Spring Cloud Sleuth, which (if my understanding is correct) uses the LazyTracingFilter bean to handle tracing concerns. This filter is registered for the ERROR dispatcher types (among others), which ensures that the tracing context is available in the ErrorController whenever it handles a request.
We are trying to upgrade to Spring Boot 3.x.x, and I have observed that the ServerHttpObservationFilter bean (which is now being used) is registered for dispatcher types REQUEST and ASYNC, but not ERROR. This means that we don't have tracing information available in our ErrorController when it is invoked.
Would it be possible to (optionally) register ServerHttpObservationFilter for the ERROR dispatcher type as well? If so, would the filter also need to return false for shouldNotFilterErrorDispatch()?
Comment From: bclozel
This won't work as discussed in https://github.com/spring-projects/spring-framework/issues/30675
We would need first to ensure that the filter works and correctly records observations with this setup. We haven't found a way to do this without breaking the observation measurement.