-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply exception type and message (#3148)
Co-authored-by: Trask Stalnaker <[email protected]>
- Loading branch information
Showing
7 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
smoke-tests/apps/OpenTelemetryApiLogBridge/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins { | ||
id("ai.smoke-test-war") | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12") { | ||
exclude("org.springframework.boot", "spring-boot-starter-tomcat") | ||
} | ||
implementation("io.opentelemetry:opentelemetry-api:1.27.0") | ||
implementation("io.opentelemetry:opentelemetry-semconv:1.27.0-alpha") | ||
} |
16 changes: 16 additions & 0 deletions
16
...LogBridge/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.smoketestapp; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
|
||
@SpringBootApplication | ||
public class SpringBootApp extends SpringBootServletInitializer { | ||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) { | ||
return applicationBuilder.sources(SpringBootApp.class); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ogBridge/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.smoketestapp; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.api.logs.Severity; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
|
||
@GetMapping("/") | ||
public String root() { | ||
return "OK"; | ||
} | ||
|
||
@GetMapping("/test-custom-exception-type-and-message") | ||
public String testCustomExceptionTypeAndMessage() { | ||
StringWriter sw = new StringWriter(); | ||
new Exception().printStackTrace(new PrintWriter(sw, true)); | ||
|
||
GlobalOpenTelemetry.get() | ||
.getLogsBridge() | ||
.get("my logger") | ||
.logRecordBuilder() | ||
.setSeverity(Severity.INFO) | ||
.setAttribute(SemanticAttributes.EXCEPTION_TYPE, "my exception type") | ||
.setAttribute( | ||
SemanticAttributes.EXCEPTION_MESSAGE, | ||
"This is an custom exception with custom exception type") | ||
.setAttribute(SemanticAttributes.EXCEPTION_STACKTRACE, sw.toString()) | ||
.emit(); | ||
return "OK!"; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...eTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiLogBridgeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.smoketest; | ||
|
||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_19; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_20; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
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.RequestData; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
@UseAgent | ||
abstract class OpenTelemetryApiLogBridgeTest { | ||
|
||
@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); | ||
|
||
@Test | ||
@TargetUri("/test-custom-exception-type-and-message") | ||
void testCustomExceptionTypeAndMessage() throws Exception { | ||
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1); | ||
Envelope rdEnvelope = rdList.get(0); | ||
|
||
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData(); | ||
assertThat(rd.getUrl()) | ||
.matches( | ||
"http://localhost:[0-9]+/OpenTelemetryApiLogBridge/test-custom-exception-type-and-message"); | ||
assertThat(rd.getResponseCode()).isEqualTo("200"); | ||
assertThat(rd.getSuccess()).isTrue(); | ||
assertThat(rd.getSource()).isNull(); | ||
assertThat(rd.getProperties()).hasSize(1); | ||
assertThat(rd.getProperties()).containsEntry("_MS.ProcessedByMetricExtractors", "True"); | ||
|
||
assertThat(rdEnvelope.getIKey()).isEqualTo("00000000-0000-0000-0000-0FEEDDADBEEF"); | ||
assertThat(rdEnvelope.getTags()) | ||
.hasEntrySatisfying("ai.internal.sdkVersion", v -> assertThat(v).startsWith("java:3.")); | ||
|
||
String operationId = rdEnvelope.getTags().get("ai.operation.id"); | ||
List<Envelope> edList = | ||
testing.mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId); | ||
assertThat(edList.size()).isNotZero(); | ||
ExceptionData ed = (ExceptionData) ((Data<?>) edList.get(0).getData()).getBaseData(); | ||
assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("my exception type"); | ||
assertThat(ed.getExceptions().get(0).getMessage()) | ||
.isEqualTo("This is an custom exception with custom exception type"); | ||
} | ||
|
||
@Environment(TOMCAT_8_JAVA_8) | ||
static class Tomcat8Java8Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_8_OPENJ9) | ||
static class Tomcat8Java8OpenJ9Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_11) | ||
static class Tomcat8Java11Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_11_OPENJ9) | ||
static class Tomcat8Java11OpenJ9Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_17) | ||
static class Tomcat8Java17Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_19) | ||
static class Tomcat8Java19Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_20) | ||
static class Tomcat8Java20Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(WILDFLY_13_JAVA_8) | ||
static class Wildfly13Java8Test extends OpenTelemetryApiLogBridgeTest {} | ||
|
||
@Environment(WILDFLY_13_JAVA_8_OPENJ9) | ||
static class Wildfly13Java8OpenJ9Test extends OpenTelemetryApiLogBridgeTest {} | ||
} |
11 changes: 11 additions & 0 deletions
11
smoke-tests/apps/OpenTelemetryApiLogBridge/src/smokeTest/resources/logback-test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="warn"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
</configuration> |