Skip to content

Commit 53eb54b

Browse files
traskgithub-actions[bot]
andauthored
Fix trace diagnostics (#2778)
Co-authored-by: github-actions[bot] <github-action[bot]@users.noreply.github.com>
1 parent f9a22ad commit 53eb54b

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AppInsightsCertificate.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ private String loadCertificates() {
8787
private String executeWithoutException(ProcessBuilder processBuilder) {
8888

8989
try {
90+
// to make sure the javaagent is not re-applied to the keytool process, which then creates
91+
// a recursive hanging
92+
// also helps to ensure other JVM args are not passed along
93+
processBuilder.environment().put("JAVA_TOOL_OPTIONS", "");
94+
processBuilder.environment().put("_JAVA_OPTIONS", "");
95+
9096
Process process = processBuilder.start();
9197
OutputStream outputStream = process.getOutputStream();
9298
PrintWriter writer =

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/CommandExecutor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ static String execute(ProcessBuilder processBuilder) {
2222
IllegalStateException exitException = null;
2323
String result = null;
2424
try {
25+
// to make sure the javaagent (and other JVM args) are not applied to the process
26+
processBuilder.environment().put("JAVA_TOOL_OPTIONS", "");
27+
processBuilder.environment().put("_JAVA_OPTIONS", "");
28+
2529
Process process = processBuilder.start();
2630
int exitValue = process.waitFor();
2731
exitException =

smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
@UseAgent
2121
abstract class CustomDimensionsTest {
2222

23-
@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
23+
// TODO (trask) find a better(?) place to test self-diagnostics trace level
24+
// instead of this seemingly ad-hoc location
25+
@RegisterExtension
26+
static final SmokeTestExtension testing =
27+
SmokeTestExtension.builder().setSelfDiagnosticsLevel("trace").build();
2428

2529
@Test
2630
@TargetUri("/test")

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtension.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class SmokeTestExtension
9191
private final boolean readOnly;
9292
private final boolean usesGlobalIngestionEndpoint;
9393
private final boolean useOld3xAgent;
94+
private final String selfDiagnosticsLevel;
9495
private final File javaagentFile;
9596

9697
public static SmokeTestExtension create() {
@@ -107,13 +108,15 @@ public static SmokeTestExtensionBuilder builder() {
107108
boolean usesGlobalIngestionEndpoint,
108109
boolean skipHealthCheck,
109110
boolean readOnly,
110-
boolean useOld3xAgent) {
111+
boolean useOld3xAgent,
112+
String selfDiagnosticsLevel) {
111113
this.skipHealthCheck = skipHealthCheck;
112114
this.readOnly = readOnly;
113115
this.dependencyContainer = dependencyContainer;
114116
this.dependencyContainerEnvVarName = dependencyContainerEnvVarName;
115117
this.usesGlobalIngestionEndpoint = usesGlobalIngestionEndpoint;
116118
this.useOld3xAgent = useOld3xAgent;
119+
this.selfDiagnosticsLevel = selfDiagnosticsLevel;
117120

118121
String javaagentPathSystemProperty =
119122
useOld3xAgent ? "ai.smoke-test.old-3x-javaagent-file" : "ai.smoke-test.javaagent-file";
@@ -369,6 +372,7 @@ protected Set<Integer> getLivenessCheckPorts() {
369372
+ FAKE_INGESTION_ENDPOINT
370373
+ ";LiveEndpoint="
371374
+ FAKE_INGESTION_ENDPOINT)
375+
.withEnv("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL", selfDiagnosticsLevel)
372376
.withNetwork(network)
373377
.withExposedPorts(8080)
374378
.withFileSystemBind(

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtensionBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class SmokeTestExtensionBuilder {
1313
private boolean skipHealthCheck;
1414
private boolean readOnly;
1515
private boolean useOld3xAgent;
16+
private String selfDiagnosticsLevel = "info";
1617

1718
public SmokeTestExtensionBuilder setDependencyContainer(
1819
String envVarName, GenericContainer<?> container) {
@@ -41,13 +42,19 @@ public SmokeTestExtensionBuilder useOld3xAgent() {
4142
return this;
4243
}
4344

45+
public SmokeTestExtensionBuilder setSelfDiagnosticsLevel(String selfDiagnosticsLevel) {
46+
this.selfDiagnosticsLevel = selfDiagnosticsLevel;
47+
return this;
48+
}
49+
4450
public SmokeTestExtension build() {
4551
return new SmokeTestExtension(
4652
dependencyContainer,
4753
dependencyContainerEnvVarName,
4854
usesGlobalIngestionEndpoint,
4955
skipHealthCheck,
5056
readOnly,
51-
useOld3xAgent);
57+
useOld3xAgent,
58+
selfDiagnosticsLevel);
5259
}
5360
}

0 commit comments

Comments
 (0)