@Override public void run() { tclient.trackException(exception, properties, metrics); } };
@Override public void exceptionCaught(String classAndMethodNames, Throwable throwable) { try { if (throwable instanceof Exception) { telemetryClient.trackException((Exception)throwable); } } catch (ThreadDeath td) { throw td; } catch (Throwable t) { } }
/** * Sends an exception record to Application Insights. Appears in "exceptions" in Analytics and Search. * @param exception The exception to log information about. */ public void trackException(Exception exception) { trackException(exception, null, null); }
protected void sendExceptionInternal(final Exception exception, final Map<String, String> properties) { final PropertyMapBuilder builder = new PropertyMapBuilder(properties); // Log that the event occurred (this log is used in testing) logger.debug(String.format("sendException(%s, %s)", exception.getMessage(), builder.toString())); if (telemetryClient != null) { telemetryClient.trackException(exception, builder.build(), null); } }
private void onException(Exception e, ServletRequest req, ServletResponse res, boolean isRequestProcessedSuccessfully) { try { InternalLogger.INSTANCE.trace("Unhandled application exception: %s", ExceptionUtils.getStackTrace(e)); if (telemetryClient != null) { telemetryClient.trackException(e); } } catch (Exception ignoreMe) { } invokeSafeOnEndRequest(req, res, isRequestProcessedSuccessfully); }
private void onException(Exception e, ServletRequest req, ServletResponse res, boolean isRequestProcessedSuccessfully) { try { InternalLogger.INSTANCE.trace("Unhandled application exception: %s", ExceptionUtils.getStackTrace(e)); if (telemetryClient != null) { telemetryClient.trackException(e); } } catch (Exception ignoreMe) { } invokeSafeOnEndRequest(req, res, isRequestProcessedSuccessfully); }
private FilterAndTelemetryClientMock createInitializedFilterWithMockTelemetryClient(boolean withTelemetryClient, boolean clientThrows) throws ServletException, NoSuchFieldException, IllegalAccessException { Filter filter = createInitializedFilter(); Field field = WebRequestTrackingFilter.class.getDeclaredField("telemetryClient"); field.setAccessible(true); TelemetryClient mockTelemetryClient = null; if (withTelemetryClient) { mockTelemetryClient = spy(new TelemetryClient()); if (clientThrows) { doThrow(new RuntimeException()).when(mockTelemetryClient).trackException(any(Exception.class)); } } field.set(filter, mockTelemetryClient); return new FilterAndTelemetryClientMock(filter, mockTelemetryClient); }
@Test public void testTrackException() { Exception exception = new Exception("Exception"); client.trackException(exception); verifyAndGetLastEventSent(); }
private void testException(FilterAndTelemetryClientMock createdData, Exception expectedException) throws NoSuchFieldException, IllegalAccessException, ServletException { try { FilterChain chain = mock(FilterChain.class); ServletRequest request = ServletUtils.generateDummyServletRequest(); ServletResponse response = ServletUtils.generateDummyServletResponse(); Mockito.doThrow(expectedException).when(chain).doFilter(eq(request), any(ServletResponse.class)); // execute createdData.filter.doFilter(request, response, chain); assertFalse("doFilter should have throw", true); } catch (Exception se) { Assert.assertSame(expectedException, se); if (createdData.mockTelemetryClient != null) { verify(createdData.mockTelemetryClient, times(1)).trackException(any(Exception.class)); } } }
@Test public void testTrackExceptionWithExceptionTelemetry() { ExceptionTelemetry telemetry = new ExceptionTelemetry(new Exception("Exception")); client.trackException(telemetry); verifyAndGetLastEventSent(); }
throw new Exception("This is only a test!"); } catch (Exception exc) { appInsights.trackException(exc); System.out.println("[6] Exception -- message=\"This is only a test!\"");
@Test public void testTrackExceptionWithPropertiesAndMetrics() { Exception exception = new Exception("Exception"); Map<String, String> properties = new HashMap<String, String>() {{ put("key", "value"); }}; Map<String, Double> metrics = new HashMap<String, Double>() {{ put("key", 1d); }}; client.trackException(exception, properties, metrics); verifyAndGetLastEventSent(); }
telemetryClient.trackException(new Exception());
telemetryClient.trackException(new Exception());