Search in sources :

Example 6 with ExceptionData

use of com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData in project ApplicationInsights-Java by microsoft.

the class TraceJavaUtilLoggingTest method testTraceJavaUtilLoggingWithExeption.

@Test
@TargetUri("traceJavaUtilLoggingWithException")
public void testTraceJavaUtilLoggingWithExeption() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    List<Envelope> edList = mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope = edList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
    assertEquals("Fake Exception", ed.getExceptions().get(0).getMessage());
    assertEquals(SeverityLevel.Error, ed.getSeverityLevel());
    assertEquals("This is an exception!", ed.getProperties().get("Logger Message"));
    assertEquals("Logger", ed.getProperties().get("SourceType"));
    assertEquals("SEVERE", ed.getProperties().get("LoggingLevel"));
    assertEquals("smoketestapp", ed.getProperties().get("LoggerName"));
    assertNotNull(ed.getProperties().get("ThreadName"));
    assertEquals(5, ed.getProperties().size());
    assertParentChild(rd, rdEnvelope, edEnvelope, "GET /TraceJavaUtilLoggingUsingAgent/traceJavaUtilLoggingWithException");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 7 with ExceptionData

use of com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData in project ApplicationInsights-Java by microsoft.

the class TraceLog4j12Test method testTraceLog4j1_2WithExeption.

@Test
@TargetUri("traceLog4j1_2WithException")
public void testTraceLog4j1_2WithExeption() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    List<Envelope> edList = mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope = edList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
    List<ExceptionDetails> details = ed.getExceptions();
    ExceptionDetails ex = details.get(0);
    assertEquals("Fake Exception", ex.getMessage());
    assertEquals(SeverityLevel.Error, ed.getSeverityLevel());
    assertEquals("This is an exception!", ed.getProperties().get("Logger Message"));
    assertEquals("Logger", ed.getProperties().get("SourceType"));
    assertEquals("ERROR", ed.getProperties().get("LoggingLevel"));
    assertEquals("smoketestapp", ed.getProperties().get("LoggerName"));
    assertNotNull(ed.getProperties().get("ThreadName"));
    assertEquals("MDC value", ed.getProperties().get("MDC key"));
    assertEquals(6, ed.getProperties().size());
    assertParentChild(rd, rdEnvelope, edEnvelope, "GET /TraceLog4j1_2UsingAgent/traceLog4j1_2WithException");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) ExceptionDetails(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 8 with ExceptionData

use of com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData in project ApplicationInsights-Java by microsoft.

the class SpringBootControllerSpansEnabledTest method testResultCodeWhenRestControllerThrows.

@Test
@TargetUri("/throwsException")
public void testResultCodeWhenRestControllerThrows() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 1, operationId);
    List<Envelope> edList = mockedIngestion.waitForItems(new Predicate<Envelope>() {

        @Override
        public boolean test(Envelope input) {
            if (!"ExceptionData".equals(input.getData().getBaseType())) {
                return false;
            }
            if (!operationId.equals(input.getTags().get("ai.operation.id"))) {
                return false;
            }
            // lastly, filter out ExceptionData captured from tomcat logger
            ExceptionData data = (ExceptionData) ((Data<?>) input.getData()).getBaseData();
            return !data.getProperties().containsKey("LoggerName");
        }
    }, 2, 10, TimeUnit.SECONDS);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope rddEnvelope1 = rddList.get(0);
    Envelope edEnvelope1 = edList.get(0);
    RequestData rd = getTelemetryDataForType(0, "RequestData");
    RemoteDependencyData rdd1 = (RemoteDependencyData) ((Data<?>) rddEnvelope1.getData()).getBaseData();
    assertEquals("GET /SpringBootTest/throwsException", rd.getName());
    assertEquals("500", rd.getResponseCode());
    assertTrue(rd.getProperties().isEmpty());
    assertFalse(rd.getSuccess());
    assertEquals("TestController.resultCodeTest", rdd1.getName());
    assertNull(rdd1.getData());
    assertEquals("InProc", rdd1.getType());
    assertNull(rdd1.getTarget());
    assertTrue(rdd1.getProperties().isEmpty());
    assertFalse(rdd1.getSuccess());
    assertParentChild(rd, rdEnvelope, rddEnvelope1, "GET /SpringBootTest/throwsException");
    assertParentChild(rdd1, rddEnvelope1, edEnvelope1, "GET /SpringBootTest/throwsException");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 9 with ExceptionData

use of com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData in project ApplicationInsights-Java by microsoft.

the class TraceLog4j2Test method testTraceLog4j2WithException.

@Test
@TargetUri("/traceLog4j2WithException")
public void testTraceLog4j2WithException() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    List<Envelope> edList = mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope = edList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
    List<ExceptionDetails> details = ed.getExceptions();
    ExceptionDetails ex = details.get(0);
    assertEquals("Fake Exception", ex.getMessage());
    assertEquals(SeverityLevel.Error, ed.getSeverityLevel());
    assertEquals("This is an exception!", ed.getProperties().get("Logger Message"));
    assertEquals("Logger", ed.getProperties().get("SourceType"));
    assertEquals("ERROR", ed.getProperties().get("LoggingLevel"));
    assertEquals("smoketestapp", ed.getProperties().get("LoggerName"));
    assertNotNull(ed.getProperties().get("ThreadName"));
    assertEquals("MDC value", ed.getProperties().get("MDC key"));
    assertEquals(6, ed.getProperties().size());
    assertParentChild(rd, rdEnvelope, edEnvelope, "GET /TraceLog4j2UsingAgent/traceLog4j2WithException");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) ExceptionDetails(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Aggregations

Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)9 ExceptionData (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData)9 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)9 Test (org.junit.Test)9 ExceptionDetails (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails)4 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)3 EventData (com.microsoft.applicationinsights.smoketest.schemav2.EventData)3 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)3 AiSmokeTest (com.microsoft.applicationinsights.smoketest.AiSmokeTest)1 TargetUri (com.microsoft.applicationinsights.smoketest.TargetUri)1 MessageData (com.microsoft.applicationinsights.smoketest.schemav2.MessageData)1 MetricData (com.microsoft.applicationinsights.smoketest.schemav2.MetricData)1 PageViewData (com.microsoft.applicationinsights.smoketest.schemav2.PageViewData)1