-
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
Exceptions caught by @ExceptionHandler are not recorded by MetricsWebFilter #23795
Comments
Right now we're recording an We're fetching the handled exception from a particular request attribute.
I don't know if we can fix those inconsistencies at the Spring Boot / Spring Framework level. Given the current WebFlux architecture, it might be challenging to apply the same approach, even with the same limitations. With that in mind, I'm wondering if we should only record the exception tag information for errors that acually bubble up to the Spring Boot error handling infrastructure. |
After discussing that point with the team, the team has decided to remove this behavior in a future version of Spring Boot (2.6.x at the earliest, targeted for now for 3.x). In general, we feel that recording that tag is in many cases not useful (we're recording exceptions that are considered as "normal" behavior for the app, for example a missing entry in the database leading to a 404) or inconsistent (see my previous comment). We still believe this behavior is useful, but on an opt-in basis by the application. This will be taken care of in #24028, well before we change this behavior for all developers. |
First, we need to take care of #24028 and wait until we're in a position to make important changes in the metrics + error handling space. At that point, we can amend the We should then thoroughly review the various exception/error handling mechanisms in Spring Framework and Spring Boot to make sure that we have a consistent support. #19525 and a broader revision of error handling might be a prerequisite to this change if we want to empower developers. |
Prior to this commit, some exceptions handled at the controller or handler function level would: * not bubble up to the Spring Boot error handling support * not be tagged as part of the request metrics This situation is inconsistent because in general, exceptions handled at the controller level can be considered as expected behavior. Also, depending on how the exception is handled, the request metrics might not be tagged with the exception. This will be reconsidered in gh-23795. This commit prepares a transition to the new situation. Developers can now opt-in and set the handled exception as a request attribute. This well-known attribute will be later read by the metrics support and used for tagging the request metrics with the exception provided. This mechanism is automatically used by the error handling support in Spring Boot. Closes gh-24028
Thanks for detailed explanation. I'd like to share personal experience about following part
|
I'm closing this issue as it's now superseded by the observability efforts in Spring Framework directly, especially with spring-projects/spring-framework#28880. The filter implementation in Framework will not use |
Dependencies
Task
Observe exceptions which led to 4xx/5xx server responses, with a help of
http.server.requests
metric.Setup
@RestController
with@RequestMapping
suspend functions@RestControllerAdvice
with multiple@ExceptionHandler(Exception::class)
regular functionsExpected behavior
On each exception caught and processed by
@ExceptionHandler(Exception::class)
, e.g.UserNotFoundException
, it should appear in/actuator/prometheus
output, e.g.http_server_requests_seconds_count{exception="UserNotFoundException",method="POST",outcome="CLIENT_ERROR",status="400",uri="/v1/users",} 1.0
This is the way it works in
spring-boot-starter-web
.Actual behavior, problem
However, this refuses to work as expected with webflux. I used same annotated components.
http_server_requests_seconds_count{exception="None",method="POST",outcome="CLIENT_ERROR",status="400",uri="/v1/users",} 1.0
Notice:
exception
this time is "None".In this case there is a call to MetricsWebFilter.onSuccess(...), which does not have exception parameter.
Desired exception tag is filled only on exceptions uncaught by @RestControllerAdvice. This may seem like a reasonable thing to do, but it is unexpected compared to web-mvc.
The text was updated successfully, but these errors were encountered: