@@ -73,23 +73,28 @@ public final class WebRequestTrackingFilter implements Filter {
7373 static {
7474 WebReflectionUtils .initialize ();
7575 }
76+
7677 // region Members
7778 // Visible for testing
78- final static String FILTER_NAME = "ApplicationInsightsWebFilter" ;
79- private final static String WEB_INF_FOLDER = "WEB-INF/" ;
79+ static final String FILTER_NAME = "ApplicationInsightsWebFilter" ;
80+ private static final String WEB_INF_FOLDER = "WEB-INF/" ;
8081
8182 private WebModulesContainer webModulesContainer ;
8283 private TelemetryClient telemetryClient ;
8384 private final List <ThreadLocalCleaner > cleaners = new LinkedList <ThreadLocalCleaner >();
8485 private String appName ;
85- private static final String AGENT_LOCATOR_INTERFACE_NAME = "com.microsoft.applicationinsights."
86- + "agent.internal.coresync.AgentNotificationsHandler" ;
86+ private static final String AGENT_LOCATOR_INTERFACE_NAME = "com.microsoft.applicationinsights.agent.internal.coresync.AgentNotificationsHandler" ;
8787 private String filterName = FILTER_NAME ;
8888
8989 /**
9090 * Constant for marking already processed request
9191 */
92- private final String ALREADY_FILTERED = "AI_FILTER_PROCESSED" ;
92+ private static final String ALREADY_FILTERED = "AI_FILTER_PROCESSED" ;
93+ /**
94+ * Request Attribute to flag if exception was thrown from servlet/downstream filter.
95+ * Value will be the caught (and rethrown) exception/throwable.
96+ */
97+ public static final String APPLICATION_INSIGHTS_CAUGHT_EXCEPTION = "AI_CAUGHT_EXCEPTION" ;
9398
9499 /**
95100 * Utility handler used to instrument request start and end
@@ -137,13 +142,13 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
137142 httpRequest .setAttribute (ALREADY_FILTERED , Boolean .TRUE );
138143 chain .doFilter (httpRequest , httpResponse );
139144 } catch (ServletException | IOException | RuntimeException e ) {
145+ httpRequest .setAttribute (APPLICATION_INSIGHTS_CAUGHT_EXCEPTION , e );
140146 handler .handleException (e );
141147 throw e ;
142148 } finally {
143149 if (httpRequest .isAsyncStarted ()) {
144150 AsyncContext context = httpRequest .getAsyncContext ();
145- AIHttpServletListener aiHttpServletListener =
146- new AIHttpServletListener (handler , requestTelemetryContext , agentBinding );
151+ AIHttpServletListener aiHttpServletListener = new AIHttpServletListener (handler , requestTelemetryContext , agentBinding );
147152 context .addListener (aiHttpServletListener , httpRequest , httpResponse );
148153 } else {
149154 handler .handleEnd (httpRequest , httpResponse , requestTelemetryContext );
0 commit comments