Skip to content

Commit 85bd47b

Browse files
authored
Add warning message if the Java agent is in the class path (#3960)
1 parent 6d18939 commit 85bd47b

File tree

1 file changed

+10
-1
lines changed
  • agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init

1 file changed

+10
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,18 @@ public void init(EarlyInitAgentConfig earlyConfig) {
122122
startupLogger.debug("JAVA_TOOL_OPTIONS: " + System.getenv("JAVA_TOOL_OPTIONS"));
123123
}
124124

125+
String classPath = System.getProperty("java.class.path");
126+
// class path null with a Spring Boot executable JAR
127+
if (classPath != null
128+
// JAR name in Maven central, the user could have renamed it
129+
&& classPath.contains("applicationinsights-agent")) {
130+
startupLogger.warn(
131+
"The applicationinsights-agent JAR is in the class path. You should remove it because it could lead to unexpected results. You should configure the Java agent with -javaagent. You can also use the runtime attachment with Spring Boot applications.");
132+
}
133+
125134
if (startupLogger.isTraceEnabled()) {
126135
startupLogger.trace("OS: " + System.getProperty("os.name"));
127-
startupLogger.trace("Classpath: " + System.getProperty("java.class.path"));
136+
startupLogger.trace("Classpath: " + classPath);
128137
startupLogger.trace("Netty versions: " + NettyVersions.extract());
129138
startupLogger.trace("Env: " + findEnvVariables());
130139
startupLogger.trace("System properties: " + findSystemProperties());

0 commit comments

Comments
 (0)