Skip to content

Commit

Permalink
Revert spring advice exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jtduffy committed Oct 11, 2023
1 parent 350a4be commit f9f6132
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
public final class TomcatServletRequestListener implements ServletRequestListener {

private static final String SERVLET_EXCEPTION_ATTRIBUTE_NAME = "jakarta.servlet.error.exception";
private static final String SPRING6_SERVLET_EXCEPTION_ATTRIBUTE_NAME = "org.springframework.web.servlet.DispatcherServlet.EXCEPTION";
private static final String REQUEST_FIELD = "request";

private final Field requestField;
Expand All @@ -45,7 +44,7 @@ private Field getRequestField() {
@CatchAndLog
@Override
public void requestDestroyed(ServletRequestEvent sre) {
Throwable exception = retrieveExceptionFromServlet(sre);
Throwable exception =(Throwable) sre.getServletRequest().getAttribute(SERVLET_EXCEPTION_ATTRIBUTE_NAME);
if (exception != null) {
AgentBridge.privateApi.reportException(exception);
}
Expand Down Expand Up @@ -98,12 +97,4 @@ private Request_Weaved getRequest(HttpServletRequest httpServletRequest) {
}
return null;
}

private Throwable retrieveExceptionFromServlet(ServletRequestEvent sre) {
//As of Spring 6, when controller advice is used for controller exception handling, the caught exception is
//now stored in the servlet attribute map with the "org.springframework.web.servlet.DispatcherServlet.EXCEPTION" key.
return (Throwable) (sre.getServletRequest().getAttribute(SERVLET_EXCEPTION_ATTRIBUTE_NAME) != null ?
sre.getServletRequest().getAttribute(SERVLET_EXCEPTION_ATTRIBUTE_NAME) :
sre.getServletRequest().getAttribute(SPRING6_SERVLET_EXCEPTION_ATTRIBUTE_NAME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SpringDispatcherPointCut(PointCutClassTransformer classTransformer) {

@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, Object dispatcher, Object[] args) {
if (RENDER_METHOD_NAME == sig.getMethodName()) {
if (RENDER_METHOD_NAME.equals(sig.getMethodName())) {
StringBuilder metricName = new StringBuilder("SpringView");
if (canSetTransactionName(transaction)) {
try {
Expand Down

0 comments on commit f9f6132

Please sign in to comment.