Skip to content

Commit a3e3d04

Browse files
committed
Add warning message if the Java agent is in the class path
1 parent 8c2d9e6 commit a3e3d04

File tree

1 file changed

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

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,19 @@ public void init(EarlyInitAgentConfig earlyConfig) {
118118
startupLogger.debug("JAVA_TOOL_OPTIONS: " + System.getenv("JAVA_TOOL_OPTIONS"));
119119
}
120120

121+
String classPath = System.getProperty("java.class.path");
122+
// class path null with a Spring Boot executable JAR
123+
if (classPath != null
124+
&& classPath.contains(
125+
"applicationinsights-agent")) { // JAR name in Maven central, the user could have
126+
// renamed it
127+
startupLogger.warn(
128+
"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.");
129+
}
130+
121131
if (startupLogger.isTraceEnabled()) {
122132
startupLogger.trace("OS: " + System.getProperty("os.name"));
123-
startupLogger.trace("Classpath: " + System.getProperty("java.class.path"));
133+
startupLogger.trace("Classpath: " + classPath);
124134
startupLogger.trace("Netty versions: " + NettyVersions.extract());
125135
startupLogger.trace("Env: " + System.getenv());
126136
startupLogger.trace("System properties: " + findSystemProperties());

0 commit comments

Comments
 (0)