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

Controller level exceptions not getting populated in HTTP server requests metrics #33731

Closed
bunty-raghani opened this issue Jan 9, 2023 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@bunty-raghani
Copy link

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)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 9, 2023
@wilkinsona
Copy link
Member

wilkinsona commented Jan 9, 2023

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.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jan 9, 2023
@bclozel
Copy link
Member

bclozel commented Jan 9, 2023

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?

@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona removed the status: waiting-for-feedback We need additional information before we can continue label Jan 9, 2023
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 9, 2023
@bclozel bclozel added this to the 3.0.x milestone Jan 9, 2023
@philwebb philwebb changed the title SB-3 - Controller level exceptions not getting populated in HTTP server requests metrics Controller level exceptions not getting populated in HTTP server requests metrics Jan 9, 2023
@bunty-raghani
Copy link
Author

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

@bunty-raghani
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants