Skip to content

Unhandled exceptions should mark Servlet observation outcome as error #29512

@jonatan-ivanov

Description

@jonatan-ivanov

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 #29398

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions