Skip to content

Commit b4345a3

Browse files
committed
Add smoke test
1 parent b7b35f0 commit b4345a3

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketestapp;
5+
6+
import javax.servlet.annotation.WebServlet;
7+
import javax.servlet.http.HttpServlet;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
11+
@WebServlet("/testWithSpanException")
12+
public class LogbackWithSpanExceptionServlet extends HttpServlet {
13+
14+
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
15+
throw new RuntimeException("Test Exception");
16+
}
17+
}

smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackDisabledTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
1010
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
11+
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData;
1112
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
1213
import java.util.List;
1314
import org.junit.jupiter.api.Test;
@@ -30,4 +31,31 @@ void testDisabled() throws Exception {
3031

3132
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
3233
}
34+
35+
@Test
36+
@TargetUri("/testWithSpanException")
37+
void testWithSpanException() throws Exception {
38+
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
39+
40+
Envelope rdEnvelope = rdList.get(0);
41+
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
42+
assertThat(rd.getName()).isEqualTo("GET /Logback/testWithSpanException");
43+
44+
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
45+
46+
// check that span exception is still captured
47+
String operationId = rdEnvelope.getTags().get("ai.operation.id");
48+
List<Envelope> edList =
49+
testing.mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId);
50+
51+
Envelope edEnvelope = edList.get(0);
52+
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
53+
54+
assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.RuntimeException");
55+
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Test Exception");
56+
assertThat(ed.getProperties()).isEmpty(); // this is not a logger-based exception
57+
58+
SmokeTestExtension.assertParentChild(
59+
rd, rdEnvelope, edEnvelope, "GET /Logback/testWithSpanException");
60+
}
3361
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketest;
5+
6+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
10+
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
11+
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData;
12+
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
13+
import java.util.List;
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.extension.RegisterExtension;
16+
17+
@Environment(TOMCAT_8_JAVA_8)
18+
@UseAgent("level_off_applicationinsights.json")
19+
class LogbackLevelOffTest {
20+
21+
@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
22+
23+
@Test
24+
@TargetUri("/test")
25+
void testDisabled() throws Exception {
26+
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
27+
28+
Envelope rdEnvelope = rdList.get(0);
29+
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
30+
assertThat(rd.getName()).isEqualTo("GET /Logback/test");
31+
32+
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
33+
}
34+
35+
@Test
36+
@TargetUri("/testWithSpanException")
37+
void testWithSpanException() throws Exception {
38+
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
39+
40+
Envelope rdEnvelope = rdList.get(0);
41+
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
42+
assertThat(rd.getName()).isEqualTo("GET /Logback/testWithSpanException");
43+
44+
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
45+
46+
// check that span exception is still captured
47+
String operationId = rdEnvelope.getTags().get("ai.operation.id");
48+
List<Envelope> edList =
49+
testing.mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId);
50+
51+
Envelope edEnvelope = edList.get(0);
52+
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
53+
54+
assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.RuntimeException");
55+
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Test Exception");
56+
assertThat(ed.getProperties()).isEmpty(); // this is not a logger-based exception
57+
58+
SmokeTestExtension.assertParentChild(
59+
rd, rdEnvelope, edEnvelope, "GET /Logback/testWithSpanException");
60+
}
61+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"role": {
3+
"name": "testrolename",
4+
"instance": "testroleinstance"
5+
},
6+
"sampling": {
7+
"percentage": 100
8+
},
9+
"instrumentation": {
10+
"logging": {
11+
"level": "off"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)