Exceptions handled at the controller level are not populated in the http.server.requests metrics.

As per the official docs, we need to set the request attribute in @ExceptionHandler method before returning a response. I tried this approach but exceptions are not included in "availableTags -> exception array".

Observed this issue only for exceptions that are handled at the controller level. For other exceptions, that are internally handled by the spring framework, such exceptions are visible in metrics.

Endpoint: /actuator/metrics/http.server.requests Spring Boot Version: 3.0.1 (also, tried 3.0.2-SNAPSHOT)

Comment From: wilkinsona

Thanks for the report. Unfortunately, your short description of the problem leaves too many unknowns for us to be able to diagnose it efficiently. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: bclozel

We introduced this attribute in #24028, since we decided to remove this behavior by default in #23795. Since the Observability support has been rewritten in Spring Boot 3.0, we cannot support this request attribute anymore since observability support is built in Spring Framework directly (and ErrorAttributes lives in Spring Boot).

I think this is an oversight and that we should have:

  • removed this request attribute completely in 3.0 as it's not supported anymore
  • updated the reference documentation to show a new code snippet that achieves the same goal:
import jakarta.servlet.http.HttpServletRequest;

import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Controller
public class MyController {

    @ExceptionHandler(CustomException.class)
    String handleCustomException(HttpServletRequest request, CustomException ex) {
    ServerHttpObservationFilter.findObservationContext(request)
            .ifPresent(context -> context.setError(exception));
        return "errorView";
    }

}

Should we consider this a bug then and apply those changes in the next maintenance version?

Comment From: wilkinsona

Thanks for filling in some blanks for me, @bclozel. @bunty-raghani there's no need for a sample now.

Should we consider this a bug then and apply those changes in the next maintenance version?

Yes, I think we should.

Comment From: bunty-raghani

Thank you @bclozel & @wilkinsona for considering this issue and for providing the required help. I tried the new code snippet and it is working fine. Also, apologies for not attaching the sample code to reproduce this issue.

Thank you once again for all your help!

Regards, Bunty Raghani

Comment From: bunty-raghani

Kindly ignore the closed and reopened message, it happened by mistake. Spring team will fix this in future versions as mentioned above.