use of com.microsoft.applicationinsights.smoketest.schemav2.Data 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");
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project ApplicationInsights-Java by microsoft.
the class TraceJavaUtilLoggingTest method testTraceJavaUtilLogging.
@Test
@TargetUri("/traceJavaUtilLogging")
public void testTraceJavaUtilLogging() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
List<Envelope> mdList = mockedIngestion.waitForMessageItemsInRequest(2);
Envelope rdEnvelope = rdList.get(0);
Envelope mdEnvelope1 = mdList.get(0);
Envelope mdEnvelope2 = mdList.get(1);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
List<MessageData> logs = mockedIngestion.getMessageDataInRequest();
logs.sort(Comparator.comparing(MessageData::getSeverityLevel));
MessageData md1 = logs.get(0);
MessageData md2 = logs.get(1);
assertEquals("This is jul warning.", md1.getMessage());
assertEquals(SeverityLevel.Warning, md1.getSeverityLevel());
assertEquals("Logger", md1.getProperties().get("SourceType"));
assertEquals("WARNING", md1.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md1.getProperties().get("LoggerName"));
assertNotNull(md1.getProperties().get("ThreadName"));
assertEquals(4, md1.getProperties().size());
assertEquals("This is jul severe.", md2.getMessage());
assertEquals(SeverityLevel.Error, md2.getSeverityLevel());
assertEquals("Logger", md2.getProperties().get("SourceType"));
assertEquals("SEVERE", md2.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md1.getProperties().get("LoggerName"));
assertNotNull(md2.getProperties().get("ThreadName"));
assertEquals(4, md2.getProperties().size());
assertParentChild(rd, rdEnvelope, mdEnvelope1, "GET /TraceJavaUtilLoggingUsingAgent/traceJavaUtilLogging");
assertParentChild(rd, rdEnvelope, mdEnvelope2, "GET /TraceJavaUtilLoggingUsingAgent/traceJavaUtilLogging");
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project ApplicationInsights-Java by microsoft.
the class GrpcTest method doSimpleTest.
@Test
@TargetUri("/simple")
public void doSimpleTest() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 2);
Envelope rdEnvelope1 = getRequestEnvelope(rdList, "GET /simple");
Envelope rdEnvelope2 = getRequestEnvelope(rdList, "example.Greeter/SayHello");
String operationId = rdEnvelope1.getTags().get("ai.operation.id");
List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 1, operationId);
// auto-collected grpc events are suppressed by exporter because they are noisy
assertEquals(0, mockedIngestion.getCountForType("MessageData", operationId));
Envelope rddEnvelope = getDependencyEnvelope(rddList, "example.Greeter/SayHello");
RequestData rd1 = (RequestData) ((Data<?>) rdEnvelope1.getData()).getBaseData();
RemoteDependencyData rdd = (RemoteDependencyData) ((Data<?>) rddEnvelope.getData()).getBaseData();
// TODO this is not correct (or at least not ideal)
// see https://msazure.visualstudio.com/One/_workitems/edit/8687985
assertEquals("grpc", rdd.getTarget());
assertTrue(rd1.getProperties().isEmpty());
assertTrue(rd1.getSuccess());
assertTrue(rdd.getProperties().isEmpty());
assertTrue(rdd.getSuccess());
// TODO (trask): verify rd2
assertParentChild(rd1, rdEnvelope1, rddEnvelope, "GET /simple");
assertParentChild(rdd.getId(), rddEnvelope, rdEnvelope2, "GET /simple", "example.Greeter/SayHello", false);
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project ApplicationInsights-Java by microsoft.
the class TraceLog4j2Test method testTraceLog4j2.
@Test
@TargetUri("/traceLog4j2")
public void testTraceLog4j2() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
List<Envelope> mdList = mockedIngestion.waitForMessageItemsInRequest(3);
Envelope rdEnvelope = rdList.get(0);
Envelope mdEnvelope1 = mdList.get(0);
Envelope mdEnvelope2 = mdList.get(1);
Envelope mdEnvelope3 = mdList.get(2);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
List<MessageData> logs = mockedIngestion.getMessageDataInRequest();
logs.sort(Comparator.comparing(MessageData::getSeverityLevel));
MessageData md1 = logs.get(0);
MessageData md2 = logs.get(1);
MessageData md3 = logs.get(2);
assertEquals("This is log4j2 warn.", md1.getMessage());
assertEquals(SeverityLevel.Warning, md1.getSeverityLevel());
assertEquals("Logger", md1.getProperties().get("SourceType"));
assertEquals("WARN", md1.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md1.getProperties().get("LoggerName"));
assertNotNull(md1.getProperties().get("ThreadName"));
assertEquals("MDC value", md1.getProperties().get("MDC key"));
assertEquals(5, md1.getProperties().size());
assertEquals("This is log4j2 error.", md2.getMessage());
assertEquals(SeverityLevel.Error, md2.getSeverityLevel());
assertEquals("Logger", md2.getProperties().get("SourceType"));
assertEquals("ERROR", md2.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md1.getProperties().get("LoggerName"));
assertNotNull(md1.getProperties().get("ThreadName"));
assertEquals(4, md2.getProperties().size());
assertEquals("This is log4j2 fatal.", md3.getMessage());
assertEquals(SeverityLevel.Critical, md3.getSeverityLevel());
assertEquals("Logger", md3.getProperties().get("SourceType"));
assertEquals("FATAL", md3.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md3.getProperties().get("LoggerName"));
assertNotNull(md3.getProperties().get("ThreadName"));
assertEquals(4, md3.getProperties().size());
assertParentChild(rd, rdEnvelope, mdEnvelope1, "GET /TraceLog4j2UsingAgent/traceLog4j2");
assertParentChild(rd, rdEnvelope, mdEnvelope2, "GET /TraceLog4j2UsingAgent/traceLog4j2");
assertParentChild(rd, rdEnvelope, mdEnvelope3, "GET /TraceLog4j2UsingAgent/traceLog4j2");
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project ApplicationInsights-Java by microsoft.
the class TraceLog4j12Test method testTraceLog4j12.
@Test
@TargetUri("/traceLog4j12")
public void testTraceLog4j12() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
List<Envelope> mdList = mockedIngestion.waitForMessageItemsInRequest(3);
Envelope rdEnvelope = rdList.get(0);
Envelope mdEnvelope1 = mdList.get(0);
Envelope mdEnvelope2 = mdList.get(1);
Envelope mdEnvelope3 = mdList.get(2);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
List<MessageData> logs = mockedIngestion.getMessageDataInRequest();
logs.sort(Comparator.comparing(MessageData::getSeverityLevel));
MessageData md1 = logs.get(0);
MessageData md2 = logs.get(1);
MessageData md3 = logs.get(2);
assertEquals("This is log4j1.2 warn.", md1.getMessage());
assertEquals(SeverityLevel.Warning, md1.getSeverityLevel());
assertEquals("Logger", md1.getProperties().get("SourceType"));
assertEquals("WARN", md1.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md1.getProperties().get("LoggerName"));
assertNotNull(md1.getProperties().get("ThreadName"));
assertEquals("MDC value", md1.getProperties().get("MDC key"));
assertEquals(5, md1.getProperties().size());
assertEquals("This is log4j1.2 error.", md2.getMessage());
assertEquals(SeverityLevel.Error, md2.getSeverityLevel());
assertEquals("Logger", md2.getProperties().get("SourceType"));
assertEquals("ERROR", md2.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md2.getProperties().get("LoggerName"));
assertNotNull(md2.getProperties().get("ThreadName"));
assertEquals(4, md2.getProperties().size());
assertEquals("This is log4j1.2 fatal.", md3.getMessage());
assertEquals(SeverityLevel.Critical, md3.getSeverityLevel());
assertEquals("Logger", md3.getProperties().get("SourceType"));
assertEquals("FATAL", md3.getProperties().get("LoggingLevel"));
assertEquals("smoketestapp", md3.getProperties().get("LoggerName"));
assertNotNull(md3.getProperties().get("ThreadName"));
assertEquals(4, md3.getProperties().size());
assertParentChild(rd, rdEnvelope, mdEnvelope1, "GET /TraceLog4j1_2UsingAgent/traceLog4j12");
assertParentChild(rd, rdEnvelope, mdEnvelope2, "GET /TraceLog4j1_2UsingAgent/traceLog4j12");
assertParentChild(rd, rdEnvelope, mdEnvelope3, "GET /TraceLog4j1_2UsingAgent/traceLog4j12");
}
Aggregations