diff --git a/smoke-tests/apps/JavaUtilLogging/src/main/java/com/microsoft/applicationinsights/smoketestapp/JavaUtilLoggingWithExceptionServlet.java b/smoke-tests/apps/JavaUtilLogging/src/main/java/com/microsoft/applicationinsights/smoketestapp/JavaUtilLoggingWithExceptionServlet.java index 5dd746f661a..2fea74e4c5b 100644 --- a/smoke-tests/apps/JavaUtilLogging/src/main/java/com/microsoft/applicationinsights/smoketestapp/JavaUtilLoggingWithExceptionServlet.java +++ b/smoke-tests/apps/JavaUtilLogging/src/main/java/com/microsoft/applicationinsights/smoketestapp/JavaUtilLoggingWithExceptionServlet.java @@ -16,6 +16,12 @@ public class JavaUtilLoggingWithExceptionServlet extends HttpServlet { private static final Logger logger = Logger.getLogger("smoketestapp"); protected void doGet(HttpServletRequest request, HttpServletResponse response) { - logger.log(Level.SEVERE, "This is an exception!", new Exception("Fake Exception")); + Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception"); + logger.log(Level.SEVERE, "This is an exception!", e); + } + + private static boolean testNullMessage(HttpServletRequest request) { + String testNullMessage = request.getParameter("test-null-message"); + return "true".equalsIgnoreCase(testNullMessage); } } diff --git a/smoke-tests/apps/JavaUtilLogging/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JavaUtilLoggingTest.java b/smoke-tests/apps/JavaUtilLogging/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JavaUtilLoggingTest.java index a8dc8740e1c..df7fb01a748 100644 --- a/smoke-tests/apps/JavaUtilLogging/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JavaUtilLoggingTest.java +++ b/smoke-tests/apps/JavaUtilLogging/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JavaUtilLoggingTest.java @@ -78,6 +78,16 @@ void test() throws Exception { @Test @TargetUri("/testWithException") void testWithException() throws Exception { + testWithException(false); + } + + @Test + @TargetUri("/testWithException?test-null-message=true") + void testWithExceptionWithNullMessage() throws Exception { + testWithException(true); + } + + private void testWithException(boolean testNullMessage) throws Exception { List rdList = testing.mockedIngestion.waitForItems("RequestData", 1); Envelope rdEnvelope = rdList.get(0); @@ -97,7 +107,11 @@ void testWithException() throws Exception { ExceptionData ed = (ExceptionData) ((Data) edEnvelope.getData()).getBaseData(); assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.Exception"); - assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Fake Exception"); + if (testNullMessage) { + assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("java.lang.Exception"); + } else { + assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Fake Exception"); + } assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR); assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!"); assertThat(ed.getProperties()).containsEntry("SourceType", "Logger"); diff --git a/smoke-tests/apps/Log4j1/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j1WithExceptionServlet.java b/smoke-tests/apps/Log4j1/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j1WithExceptionServlet.java index 501a362fc33..eeaf5b64c7d 100644 --- a/smoke-tests/apps/Log4j1/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j1WithExceptionServlet.java +++ b/smoke-tests/apps/Log4j1/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j1WithExceptionServlet.java @@ -35,7 +35,13 @@ public class Log4j1WithExceptionServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) { MDC.put("MDC key", "MDC value"); - logger.error("This is an exception!", new Exception("Fake Exception")); + Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception"); + logger.error("This is an exception!", e); MDC.remove("MDC key"); } + + private static boolean testNullMessage(HttpServletRequest request) { + String testNullMessage = request.getParameter("test-null-message"); + return "true".equalsIgnoreCase(testNullMessage); + } } diff --git a/smoke-tests/apps/Log4j1/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j1Test.java b/smoke-tests/apps/Log4j1/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j1Test.java index 66c6d782f2e..01a208379cd 100644 --- a/smoke-tests/apps/Log4j1/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j1Test.java +++ b/smoke-tests/apps/Log4j1/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j1Test.java @@ -99,6 +99,16 @@ private void logDisableMessage() { @Test @TargetUri("/testWithException") void testWithException() throws Exception { + testWithException(false); + } + + @Test + @TargetUri("/testWithException?test-null-message=true") + void testWithExceptionWithNullMessage() throws Exception { + testWithException(true); + } + + private void testWithException(boolean testNullMessage) throws Exception { List rdList = testing.mockedIngestion.waitForItems("RequestData", 1); Envelope rdEnvelope = rdList.get(0); @@ -119,7 +129,11 @@ void testWithException() throws Exception { ExceptionDetails ex = details.get(0); assertThat(ex.getTypeName()).isEqualTo("java.lang.Exception"); - assertThat(ex.getMessage()).isEqualTo("Fake Exception"); + if (testNullMessage) { + assertThat(ex.getMessage()).isEqualTo("java.lang.Exception"); + } else { + assertThat(ex.getMessage()).isEqualTo("Fake Exception"); + } assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR); assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!"); assertThat(ed.getProperties()).containsEntry("SourceType", "Logger"); diff --git a/smoke-tests/apps/Log4j2/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j2WithExceptionServlet.java b/smoke-tests/apps/Log4j2/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j2WithExceptionServlet.java index bd704b2e340..bcdb6d026db 100644 --- a/smoke-tests/apps/Log4j2/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j2WithExceptionServlet.java +++ b/smoke-tests/apps/Log4j2/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j2WithExceptionServlet.java @@ -18,7 +18,13 @@ public class Log4j2WithExceptionServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) { ThreadContext.put("MDC key", "MDC value"); - logger.error("This is an exception!", new Exception("Fake Exception")); + Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception"); + logger.error("This is an exception!", e); ThreadContext.remove("MDC key"); } + + private static boolean testNullMessage(HttpServletRequest request) { + String testNullMessage = request.getParameter("test-null-message"); + return "true".equalsIgnoreCase(testNullMessage); + } } diff --git a/smoke-tests/apps/Log4j2/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j2Test.java b/smoke-tests/apps/Log4j2/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j2Test.java index 86f51b7b7dd..730738aa68c 100644 --- a/smoke-tests/apps/Log4j2/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j2Test.java +++ b/smoke-tests/apps/Log4j2/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j2Test.java @@ -110,6 +110,16 @@ void test() throws Exception { @Test @TargetUri("/testWithException") void testWithException() throws Exception { + testWithException(false); + } + + @Test + @TargetUri("/testWithException?test-null-message=true") + void testWithExceptionWithNullMessage() throws Exception { + testWithException(true); + } + + private void testWithException(boolean testNullMessage) throws Exception { List rdList = testing.mockedIngestion.waitForItems("RequestData", 1); Envelope rdEnvelope = rdList.get(0); @@ -130,7 +140,11 @@ void testWithException() throws Exception { ExceptionDetails ex = details.get(0); assertThat(ex.getTypeName()).isEqualTo("java.lang.Exception"); - assertThat(ex.getMessage()).isEqualTo("Fake Exception"); + if (testNullMessage) { + assertThat(ex.getMessage()).isEqualTo("java.lang.Exception"); + } else { + assertThat(ex.getMessage()).isEqualTo("Fake Exception"); + } assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR); assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!"); assertThat(ed.getProperties()).containsEntry("SourceType", "Logger"); diff --git a/smoke-tests/apps/Logback/src/main/java/com/microsoft/applicationinsights/smoketestapp/LogbackWithExceptionServlet.java b/smoke-tests/apps/Logback/src/main/java/com/microsoft/applicationinsights/smoketestapp/LogbackWithExceptionServlet.java index 1b0dac3db65..889eb86ada8 100644 --- a/smoke-tests/apps/Logback/src/main/java/com/microsoft/applicationinsights/smoketestapp/LogbackWithExceptionServlet.java +++ b/smoke-tests/apps/Logback/src/main/java/com/microsoft/applicationinsights/smoketestapp/LogbackWithExceptionServlet.java @@ -18,7 +18,13 @@ public class LogbackWithExceptionServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) { MDC.put("MDC key", "MDC value"); - logger.error("This is an exception!", new Exception("Fake Exception")); + Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception"); + logger.error("This is an exception!", e); MDC.remove("MDC key"); } + + private static boolean testNullMessage(HttpServletRequest request) { + String testNullMessage = request.getParameter("test-null-message"); + return "true".equalsIgnoreCase(testNullMessage); + } } diff --git a/smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackTest.java b/smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackTest.java index 17409b143ef..bbadcf380a6 100644 --- a/smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackTest.java +++ b/smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackTest.java @@ -138,7 +138,7 @@ void testWithException() { "ClassName", "com.microsoft.applicationinsights.smoketestapp.LogbackWithExceptionServlet") .hasProperty("MethodName", "doGet") - .hasProperty("LineNumber", "21") + .hasProperty("LineNumber", "22") .hasPropertiesSize(9))); } else { testing.waitAndAssertTrace(