Affects: 6.0.0
If micrometer-observation is set-up and if I throw an exception from a controller:
@GetMapping("/trouble")
String trouble() {
throw new IllegalStateException("Noooooo!");
}
This is the response I get:
❯ http :8080/trouble
HTTP/1.1 500
Connection: close
Content-Type: application/json
Date: Thu, 17 Nov 2022 22:01:37 GMT
Transfer-Encoding: chunked
{
"error": "Internal Server Error",
"path": "/trouble",
"status": 500,
"timestamp": "2022-11-17T22:01:37.155+00:00"
}
Please notice that the status is 500
.
If I check the prometheus output after this single call, this is what I get:
http_server_requests_seconds_count{error="IllegalStateException",exception="IllegalStateException",method="GET",outcome="SUCCESS",status="200",uri="/trouble",} 2.0
The issues:
- outcome="SUCCESS"
I think should be SERVER_ERROR
but not SUCCESS
- status="200"
This should be 500
- 2.0
This should be 1.0
, also, every subsequent request increases this counter by 2.
The happy-path scenario works as expected, only if I throw out an exception from the controller does this.
The metrics endpoint shows the same: /actuator/metrics/http.server.requests?tag=error:IllegalStateException
If I register an @ExceptionHandler
, everything works as expected:
@ExceptionHandler(IllegalStateException.class)
ProblemDetail handleIllegalState(IllegalStateException exception) {
ProblemDetail problemDetail = ProblemDetail.forStatus(HttpStatus.INTERNAL_SERVER_ERROR);
problemDetail.setTitle(exception.getMessage());
return problemDetail;
}
This might be connected to https://github.com/spring-projects/spring-framework/issues/29398