Skip to content

Provide a request attribute for storing exception info for tagging purposes #24028

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

Closed
bclozel opened this issue Nov 4, 2020 · 0 comments
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Nov 4, 2020

As part of #23795, we've found that errors handled by the web infrastructure are inconsistently tagged by our metrics support: an "exception" tag is added too broadly, and only in some cases.

Since #23795 will remove that behavior by default, we'd like to provide a way for developers to still get that behavior on an opt-in basis.

We should provide a request attribute for both MVC and WebFlux that developers can use and set to the exception being handled by the application code. Right now we have a similar (yet private) mechanism in both implementations of DefaultErrorAttributes that stores the exception as early as possible in an attribute.

Developers could then opt-in and store the exception if they wish to:

@ExceptionHandler(MyException.class)
public String myExceptionHandler(HttpServletRequest req, MyException exc) {
  req.setAttribute(ErrorAttributes.EXCEPTION, exc);
  return " fallback"
}

In this case, the metrics infrastructure would add the "exception" tag to the recorded metric.

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

No branches or pull requests

1 participant