Skip to content

Incorrect HTTP status recorded when using custom exception handler #924

@danielksb

Description

@danielksb

Expected Behavior

When running a Micronaut server with a custom exception handler that maps specific exceptions to HTTP statuses other than 500, the metrics incorrectly record the status as 500. This issue arises when using Micronaut versions 4.7.x and above, whereas the expected behavior was observed in version 4.6.x.

Given

  • an exception "DemoException"
  • an endpoint "GET /api/error" which triggers the exception
  • a CustomExceptionHandler implementing ExceptionHandler<DemoException, HttpResponse> responding with http status 400

Upon invoking the endpoint that triggers the DemoException, the expected metric should be:

http_server_requests_seconds_count{exception="none",method="GET",status="400",uri="/api/error"} 1

Actual Behaviour

Instead of recording the expected status, the metric is:

http_server_requests_seconds_count{exception="DemoException",method="GET",status="500",uri="/api/error"} 1

Steps To Reproduce

Please see the example in the repository below.

Environment Information

  • Previous Version: This behavior was functioning correctly in Micronaut version 4.6.x.
  • Current Version: The issue began occurring with the release of Micronaut version 4.7.x and continues in subsequent versions.

Example Application

https://github.com/danielksb/micronaut-demo-micrometer-bug

Version

4.7.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions