Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
import com.microsoft.applicationinsights.smoketest.schemav2.EventData;
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData;
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails;
import com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData;
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
import com.microsoft.applicationinsights.smoketest.schemav2.SeverityLevel;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -71,6 +74,10 @@ void testResultCodeWhenRestControllerThrows() throws Exception {
RequestData rd = testing.getTelemetryDataForType(0, "RequestData");
RemoteDependencyData rdd1 =
(RemoteDependencyData) ((Data<?>) rddEnvelope1.getData()).getBaseData();
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope1.getData()).getBaseData();

List<ExceptionDetails> details = ed.getExceptions();
ExceptionDetails ex = details.get(0);

assertThat(rd.getName()).isEqualTo("GET /SpringBoot/throwsException");
assertThat(rd.getResponseCode()).isEqualTo("500");
Expand All @@ -85,6 +92,17 @@ void testResultCodeWhenRestControllerThrows() throws Exception {
assertThat(rdd1.getProperties()).isEmpty();
assertThat(rdd1.getSuccess()).isFalse();

assertThat(ex.getTypeName()).isEqualTo("javax.servlet.ServletException");
assertThat(ex.getMessage()).isEqualTo("This is an exception");
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
assertThat(ed.getProperties())
.containsKey("Logger Message"); // specific message varies by app server
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");
assertThat(ed.getProperties())
.containsKey("LoggerName"); // specific logger varies by app server
assertThat(ed.getProperties()).containsKey("ThreadName");
assertThat(ed.getProperties()).hasSize(4);

SmokeTestExtension.assertParentChild(
rd, rdEnvelope, edEnvelope1, "GET /SpringBoot/throwsException");
SmokeTestExtension.assertParentChild(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
import com.microsoft.applicationinsights.smoketest.schemav2.EventData;
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData;
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails;
import com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData;
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
import com.microsoft.applicationinsights.smoketest.schemav2.SeverityLevel;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -63,17 +66,34 @@ void testResultCodeWhenRestControllerThrows() throws Exception {

Envelope edEnvelope1 = exceptions.get(0);

// assert on edEnvelope1

assertThat(rdEnvelope.getSampleRate()).isNull();
assertThat(edEnvelope1.getSampleRate()).isNull();

RequestData rd = testing.getTelemetryDataForType(0, "RequestData");
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope1.getData()).getBaseData();

List<ExceptionDetails> details = ed.getExceptions();
ExceptionDetails ex = details.get(0);

assertThat(rd.getName()).isEqualTo("GET /SpringBoot/throwsException");
assertThat(rd.getResponseCode()).isEqualTo("500");
assertThat(rd.getProperties())
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
assertThat(rd.getSuccess()).isFalse();

assertThat(ex.getTypeName()).isEqualTo("javax.servlet.ServletException");
assertThat(ex.getMessage()).isEqualTo("This is an exception");
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
assertThat(ed.getProperties())
.containsKey("Logger Message"); // specific message varies by app server
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");
assertThat(ed.getProperties())
.containsKey("LoggerName"); // specific logger varies by app server
assertThat(ed.getProperties()).containsKey("ThreadName");
assertThat(ed.getProperties()).hasSize(4);

SmokeTestExtension.assertParentChild(
rd, rdEnvelope, edEnvelope1, "GET /SpringBoot/throwsException");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ protected SpringApplicationBuilder configure(SpringApplicationBuilder applicatio
public void fixedRateScheduler() {
System.out.println("Hello world.");
}

@Scheduled(fixedRate = 100)
public void exceptional() {
throw new RuntimeException("exceptional");
}
Comment on lines +26 to +29
Copy link
Member Author

@trask trask Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we were missing a non-Servlet test that captures an exception on a "request" telemetry

while Servlets do capture an exception in OTel, we suppress the exception if it is identical to the logged exception that is also captured (see #3555)

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

import com.microsoft.applicationinsights.smoketest.schemav2.Data;
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData;
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails;
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
import com.microsoft.applicationinsights.smoketest.schemav2.SeverityLevel;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -68,6 +72,41 @@ public boolean test(Envelope input) {
2,
10,
TimeUnit.SECONDS);

List<Envelope> exceptionEnvelopes =
testing.mockedIngestion.getItemsEnvelopeDataType("ExceptionData");

assertThat(exceptionEnvelopes)
.anySatisfy(
envelope -> {
ExceptionData ed = (ExceptionData) ((Data<?>) envelope.getData()).getBaseData();
List<ExceptionDetails> details = ed.getExceptions();
ExceptionDetails ex = details.get(0);
assertThat(ex.getTypeName()).isEqualTo("java.lang.RuntimeException");
assertThat(ex.getMessage()).isEqualTo("exceptional");
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
assertThat(ed.getProperties())
.containsEntry("Logger Message", "Unexpected error occurred in scheduled task");
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");
assertThat(ed.getProperties())
.containsEntry(
"LoggerName",
"org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler");
assertThat(ed.getProperties()).containsKey("ThreadName");
assertThat(ed.getProperties()).hasSize(4);
});

assertThat(exceptionEnvelopes)
.anySatisfy(
envelope -> {
ExceptionData ed = (ExceptionData) ((Data<?>) envelope.getData()).getBaseData();
List<ExceptionDetails> details = ed.getExceptions();
ExceptionDetails ex = details.get(0);
assertThat(ex.getTypeName()).isEqualTo("java.lang.RuntimeException");
assertThat(ex.getMessage()).isEqualTo("exceptional");
assertThat(ed.getSeverityLevel()).isNull();
assertThat(ed.getProperties()).isEmpty();
});
}

@Environment(TOMCAT_8_JAVA_8)
Expand Down
Loading