Search in sources :

Example 1 with ExceptionData

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

the class SpringBootTest 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> 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");
        }
    }, 1, 10, TimeUnit.SECONDS);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope1 = edList.get(0);
    RequestData rd = getTelemetryDataForType(0, "RequestData");
    assertEquals("GET /SpringBootTest/throwsException", rd.getName());
    assertEquals("500", rd.getResponseCode());
    assertTrue(rd.getProperties().isEmpty());
    assertFalse(rd.getSuccess());
    assertParentChild(rd, rdEnvelope, 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) 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 2 with ExceptionData

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

the class TraceLogBackTest method testTraceLogBackWithExeption.

@Test
@TargetUri("traceLogBackWithException")
public void testTraceLogBackWithExeption() 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("ERROR", ed.getProperties().get("LoggingLevel"));
    assertEquals("smoketestapp", ed.getProperties().get("LoggerName"));
    assertNotNull(ed.getProperties().get("ThreadName"));
    // TODO add MDC instrumentation for jboss logging
    if (!currentImageName.contains("wildfly")) {
        assertEquals("MDC value", ed.getProperties().get("MDC key"));
        assertEquals(6, ed.getProperties().size());
    } else {
        assertEquals(5, ed.getProperties().size());
    }
    assertParentChild(rd, rdEnvelope, edEnvelope, "GET /TraceLogBackUsingAgent/traceLogBackWithException");
}
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 3 with ExceptionData

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

the class CustomInstrumentationTest method customInstrumentationThree.

@Test
@TargetUri("/customInstrumentationThree")
public void customInstrumentationThree() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    List<Envelope> rddList = mockedIngestion.waitForItemsInRequest("RemoteDependencyData", 1);
    List<Envelope> edList = mockedIngestion.waitForItemsInRequest("ExceptionData", 1);
    Envelope rdEnvelope = rdList.get(0);
    Envelope rddEnvelope = rddList.get(0);
    Envelope edEnvelope = edList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    RemoteDependencyData rdd = (RemoteDependencyData) ((Data<?>) rddEnvelope.getData()).getBaseData();
    ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
    assertTrue(rd.getSuccess());
    assertEquals(rdd.getName(), "com/microsoft/applicationinsights/smoketestapp/TargetObject.three");
    assertEquals(rdd.getType(), "OTHER");
    assertEquals(rdd.getSuccess(), false);
    List<ExceptionDetails> exceptions = ed.getExceptions();
    assertEquals(exceptions.size(), 1);
    assertEquals(exceptions.get(0).getMessage(), "Three");
    assertParentChild(rd, rdEnvelope, rddEnvelope, "GET /CustomInstrumentation/*");
    assertParentChild(rd, rdEnvelope, edEnvelope, "GET /CustomInstrumentation/*");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) ExceptionDetails(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) AiSmokeTest(com.microsoft.applicationinsights.smoketest.AiSmokeTest) Test(org.junit.Test) TargetUri(com.microsoft.applicationinsights.smoketest.TargetUri)

Example 4 with ExceptionData

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

the class CoreAndFilterTests method testAutoExceptionWithFailedRequest.

@Test
@TargetUri("/autoExceptionWithFailedRequest")
public void testAutoExceptionWithFailedRequest() 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.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");
        }
    }, 1, 10, TimeUnit.SECONDS);
    Envelope edEnvelope = edList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
    assertFalse(rd.getSuccess());
    ExceptionDetails details = getExceptionDetails(ed);
    assertEquals("This is a auto thrown exception !", details.getMessage());
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) PageViewData(com.microsoft.applicationinsights.smoketest.schemav2.PageViewData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) ExceptionDetails(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 5 with ExceptionData

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

the class CoreAndFilterTests method testTrackException.

@Test
@TargetUri("/trackException")
public void testTrackException() 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", 3, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope1 = edList.get(0);
    Envelope edEnvelope2 = edList.get(1);
    Envelope edEnvelope3 = edList.get(2);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    final String expectedName = "This is track exception.";
    final String expectedProperties = "value";
    final Double expectedMetrice = 1d;
    List<ExceptionData> exceptions = mockedIngestion.getTelemetryDataByTypeInRequest("ExceptionData");
    assertThat(exceptions, hasItem(hasException(withMessage(expectedName))));
    assertThat(exceptions, hasItem(allOf(hasException(withMessage(expectedName)), ExceptionDataMatchers.hasProperty("key", expectedProperties), hasMeasurement("key", expectedMetrice))));
    assertThat(exceptions, hasItem(allOf(hasException(withMessage(expectedName)), hasSeverityLevel(SeverityLevel.Error))));
    assertParentChild(rd, rdEnvelope, edEnvelope1, "GET /CoreAndFilter/trackException");
    assertParentChild(rd, rdEnvelope, edEnvelope2, "GET /CoreAndFilter/trackException");
    assertParentChild(rd, rdEnvelope, edEnvelope3, "GET /CoreAndFilter/trackException");
}
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)

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