Skip to content

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

@bclozel

Description

@bclozel

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions