Skip to content
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

Unhandled exceptions should mark Servlet observation outcome as error #29512

Closed
jonatan-ivanov opened this issue Nov 17, 2022 · 0 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: observability An issue related to observability and tracing type: bug A general bug
Milestone

Comments

@jonatan-ivanov
Copy link
Member

jonatan-ivanov commented Nov 17, 2022

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 17, 2022
@bclozel bclozel self-assigned this Nov 18, 2022
@bclozel bclozel added type: bug A general bug theme: observability An issue related to observability and tracing and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 18, 2022
@bclozel bclozel added this to the 6.0.1 milestone Nov 18, 2022
@bclozel bclozel changed the title Metrics are off in case of controller errors Unhandled exceptions should mark Servlet observation outcome as error Nov 18, 2022
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: observability An issue related to observability and tracing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants