Skip to content

Commit a144d83

Browse files
committed
Test null messages
1 parent 342f696 commit a144d83

File tree

13 files changed

+170
-39
lines changed

13 files changed

+170
-39
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
# Script to build and install azure-monitor-opentelemetry-autoconfigure dependency
4+
# from a specified GitHub repository and branch
5+
6+
set -e
7+
8+
echo "Building azure-monitor-opentelemetry-autoconfigure from $AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE"
9+
10+
# Parse repo and branch from format "owner/repo:branch"
11+
REPO_BRANCH="$AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE"
12+
REPO=$(echo "$REPO_BRANCH" | cut -d':' -f1)
13+
BRANCH=$(echo "$REPO_BRANCH" | cut -d':' -f2)
14+
15+
echo "Repository: $REPO"
16+
echo "Branch: $BRANCH"
17+
18+
# Clone the repository
19+
echo "Cloning repository..."
20+
git clone https://github.com/$REPO.git azure-sdk-temp
21+
cd azure-sdk-temp
22+
git checkout $BRANCH
23+
24+
# Build and install the azure-monitor-opentelemetry-autoconfigure module
25+
echo "Building and installing azure-monitor-opentelemetry-autoconfigure..."
26+
mvn clean install -DskipTests -pl sdk/monitor/azure-monitor-opentelemetry-autoconfigure -am
27+
28+
# Get the version that was just built and installed
29+
echo "Determining installed version..."
30+
INSTALLED_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -pl sdk/monitor/azure-monitor-opentelemetry-autoconfigure)
31+
echo "Installed version: $INSTALLED_VERSION"
32+
33+
# Clean up
34+
echo "Cleaning up..."
35+
cd ..
36+
rm -rf azure-sdk-temp
37+
38+
# Update dependency versions in the current project
39+
echo "Updating dependency versions in project files..."
40+
41+
# Update agent-tooling build.gradle.kts
42+
if [ -f "agent/agent-tooling/build.gradle.kts" ]; then
43+
sed -i "s/com\.azure:azure-monitor-opentelemetry-autoconfigure:[^\"]\+/com.azure:azure-monitor-opentelemetry-autoconfigure:$INSTALLED_VERSION/g" agent/agent-tooling/build.gradle.kts
44+
echo "Updated agent/agent-tooling/build.gradle.kts"
45+
fi
46+
47+
# Update smoke-tests framework build.gradle.kts
48+
if [ -f "smoke-tests/framework/build.gradle.kts" ]; then
49+
sed -i "s/com\.azure:azure-monitor-opentelemetry-autoconfigure:[^\"]\+/com.azure:azure-monitor-opentelemetry-autoconfigure:$INSTALLED_VERSION/g" smoke-tests/framework/build.gradle.kts
50+
echo "Updated smoke-tests/framework/build.gradle.kts"
51+
fi
52+
53+
./gradlew resolveAndLockAll --write-locks
54+
./gradlew generateLicenseReport --no-build-cache
55+
56+
# this is needed to make license report pass
57+
git commit -a -m "update azure-monitor-opentelemetry-autoconfigure dependency to $INSTALLED_VERSION"
58+
59+
echo "azure-monitor-opentelemetry-autoconfigure dependency build completed successfully"
60+
echo "All project files updated to use version: $INSTALLED_VERSION"

.github/workflows/build-common.yml

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ on:
88
required: false
99

1010
env:
11-
EXPORTER_VERSION: 1.1.0 # to be updated with the latest version
11+
# set this to <repo>:<branch/sha> to build and test with an unreleased
12+
# version of the azure-monitor-opentelemetry-autoconfigure dependency
13+
AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE: Azure/azure-sdk-for-java:main
1214

1315
jobs:
1416
spotless:
@@ -46,12 +48,9 @@ jobs:
4648
distribution: temurin
4749
java-version: 17
4850

49-
- name: Using a local standalone exporter dependency?
50-
if: ${{ hashFiles('azure-monitor-opentelemetry-autoconfigure-1.0.0-beta.*.jar') != '' }}
51-
run: |
52-
echo "exporter_version: ${{ env.EXPORTER_VERSION }}"
53-
mvn -version
54-
mvn install:install-file -Dfile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.jar" -DpomFile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.pom" -DgroupId="com.azure" -DartifactId="azure-monitor-opentelemetry-autoconfigure" -Dversion="${{ env.EXPORTER_VERSION }}"
51+
- name: Build and install azure-monitor-opentelemetry-autoconfigure dependency
52+
if: env.AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE != ''
53+
run: ./.github/scripts/build-azure-monitor-dependency.sh
5554

5655
- name: Setup Gradle
5756
uses: gradle/actions/setup-gradle@v4
@@ -93,12 +92,10 @@ jobs:
9392
distribution: temurin
9493
java-version: 17
9594

96-
- name: Using a local standalone exporter dependency?
97-
if: ${{ hashFiles('azure-monitor-opentelemetry-autoconfigure-1.0.0-beta.*.jar') != '' }}
98-
run: |
99-
echo "exporter_version: ${{ env.EXPORTER_VERSION }}"
100-
mvn -version
101-
mvn install:install-file -Dfile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.jar" -DpomFile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.pom" -DgroupId="com.azure" -DartifactId="azure-monitor-opentelemetry-autoconfigure" -Dversion="${{ env.EXPORTER_VERSION }}"
95+
- name: Build and install azure-monitor-opentelemetry-autoconfigure dependency
96+
if: env.AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE != ''
97+
shell: bash
98+
run: ./.github/scripts/build-azure-monitor-dependency.sh
10299

103100
- name: Setup Gradle
104101
uses: gradle/actions/setup-gradle@v4
@@ -165,12 +162,10 @@ jobs:
165162
distribution: temurin
166163
java-version: 17
167164

168-
- name: Using a local standalone exporter dependency?
169-
if: ${{ hashFiles('azure-monitor-opentelemetry-autoconfigure-1.0.0-beta.*.jar') != '' }}
170-
run: |
171-
echo "exporter_version: ${{ env.EXPORTER_VERSION }}"
172-
mvn -version
173-
mvn install:install-file -Dfile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.jar" -DpomFile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.pom" -DgroupId="com.azure" -DartifactId="azure-monitor-opentelemetry-autoconfigure" -Dversion="${{ env.EXPORTER_VERSION }}"
165+
- name: Build and install azure-monitor-opentelemetry-autoconfigure dependency
166+
if: env.AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE != ''
167+
shell: bash
168+
run: ./.github/scripts/build-azure-monitor-dependency.sh
174169

175170
- name: Setup Gradle
176171
uses: gradle/actions/setup-gradle@v4
@@ -239,12 +234,9 @@ jobs:
239234
distribution: temurin
240235
java-version: 17
241236

242-
- name: Using a local standalone exporter dependency?
243-
if: ${{ hashFiles('azure-monitor-opentelemetry-autoconfigure-1.0.0-beta.*.jar') != '' }}
244-
run: |
245-
echo "exporter_version: ${{ env.EXPORTER_VERSION }}"
246-
mvn -version
247-
mvn install:install-file -Dfile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.jar" -DpomFile="azure-monitor-opentelemetry-autoconfigure-${{ env.EXPORTER_VERSION }}.pom" -DgroupId="com.azure" -DartifactId="azure-monitor-opentelemetry-autoconfigure" -Dversion="${{ env.EXPORTER_VERSION }}"
237+
- name: Build and install azure-monitor-opentelemetry-autoconfigure dependency
238+
if: env.AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE != ''
239+
run: ./.github/scripts/build-azure-monitor-dependency.sh
248240

249241
- name: Setup Gradle
250242
uses: gradle/actions/setup-gradle@v4

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ build/
66
# Intellij
77
/.idea/
88

9-
# Visual Studio
10-
.vs
9+
# VSCode
10+
/.vscode/
11+
bin/

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ javaPlatform {
8484

8585
dependencies {
8686
for (bom in DEPENDENCY_BOMS) {
87-
api(enforcedPlatform(bom))
87+
api(platform(bom))
8888
val split = bom.split(':')
8989
dependencyVersions[split[0]] = split[2]
9090
}

smoke-tests/apps/JavaUtilLogging/src/main/java/com/microsoft/applicationinsights/smoketestapp/JavaUtilLoggingWithExceptionServlet.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public class JavaUtilLoggingWithExceptionServlet extends HttpServlet {
1616
private static final Logger logger = Logger.getLogger("smoketestapp");
1717

1818
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
19-
logger.log(Level.SEVERE, "This is an exception!", new Exception("Fake Exception"));
19+
Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception");
20+
logger.log(Level.SEVERE, "This is an exception!", e);
21+
}
22+
23+
private static boolean testNullMessage(HttpServletRequest request) {
24+
String testNullMessage = request.getParameter("test-null-message");
25+
return "true".equalsIgnoreCase(testNullMessage);
2026
}
2127
}

smoke-tests/apps/JavaUtilLogging/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JavaUtilLoggingTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ void test() throws Exception {
7878
@Test
7979
@TargetUri("/testWithException")
8080
void testWithException() throws Exception {
81+
testWithException(false);
82+
}
83+
84+
@Test
85+
@TargetUri("/testWithException?test-null-message=true")
86+
void testWithExceptionWithNullMessage() throws Exception {
87+
testWithException(true);
88+
}
89+
90+
private void testWithException(boolean testNullMessage) throws Exception {
8191
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
8292

8393
Envelope rdEnvelope = rdList.get(0);
@@ -97,7 +107,11 @@ void testWithException() throws Exception {
97107
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
98108

99109
assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.Exception");
100-
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Fake Exception");
110+
if (testNullMessage) {
111+
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("java.lang.Exception");
112+
} else {
113+
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Fake Exception");
114+
}
101115
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
102116
assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!");
103117
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");

smoke-tests/apps/LiveMetrics/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ dependencies {
66
smokeTestImplementation("org.awaitility:awaitility:4.2.0")
77
implementation("log4j:log4j:1.2.17")
88
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations:1.22.1")
9-
implementation("com.azure:azure-json:1.0.0")
10-
implementation("com.azure:azure-monitor-opentelemetry-autoconfigure:1.1.0")
119
}

smoke-tests/apps/Log4j1/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j1WithExceptionServlet.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ public class Log4j1WithExceptionServlet extends HttpServlet {
3535
@Override
3636
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
3737
MDC.put("MDC key", "MDC value");
38-
logger.error("This is an exception!", new Exception("Fake Exception"));
38+
Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception");
39+
logger.error("This is an exception!", e);
3940
MDC.remove("MDC key");
4041
}
42+
43+
private static boolean testNullMessage(HttpServletRequest request) {
44+
String testNullMessage = request.getParameter("test-null-message");
45+
return "true".equalsIgnoreCase(testNullMessage);
46+
}
4147
}

smoke-tests/apps/Log4j1/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j1Test.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ private void logDisableMessage() {
9999
@Test
100100
@TargetUri("/testWithException")
101101
void testWithException() throws Exception {
102+
testWithException(false);
103+
}
104+
105+
@Test
106+
@TargetUri("/testWithException?test-null-message=true")
107+
void testWithExceptionWithNullMessage() throws Exception {
108+
testWithException(true);
109+
}
110+
111+
private void testWithException(boolean testNullMessage) throws Exception {
102112
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
103113

104114
Envelope rdEnvelope = rdList.get(0);
@@ -119,7 +129,11 @@ void testWithException() throws Exception {
119129
ExceptionDetails ex = details.get(0);
120130

121131
assertThat(ex.getTypeName()).isEqualTo("java.lang.Exception");
122-
assertThat(ex.getMessage()).isEqualTo("Fake Exception");
132+
if (testNullMessage) {
133+
assertThat(ex.getMessage()).isEqualTo("java.lang.Exception");
134+
} else {
135+
assertThat(ex.getMessage()).isEqualTo("Fake Exception");
136+
}
123137
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
124138
assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!");
125139
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");

smoke-tests/apps/Log4j2/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j2WithExceptionServlet.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public class Log4j2WithExceptionServlet extends HttpServlet {
1818

1919
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
2020
ThreadContext.put("MDC key", "MDC value");
21-
logger.error("This is an exception!", new Exception("Fake Exception"));
21+
Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception");
22+
logger.error("This is an exception!", e);
2223
ThreadContext.remove("MDC key");
2324
}
25+
26+
private static boolean testNullMessage(HttpServletRequest request) {
27+
String testNullMessage = request.getParameter("test-null-message");
28+
return "true".equalsIgnoreCase(testNullMessage);
29+
}
2430
}

0 commit comments

Comments
 (0)