Reputation: 581
The documented way to add Azure Monitor OpenTelemetry to Java application is by downloading applicationinsights-agent-3.2.11.jar and using the following: -javaagent:path/to/applicationinsights-agent-3.2.11.jar.
So in Spring Boot, the way it could possibly be run:
java -javaagent:path/to/applicationinsights-agent-3.2.11.jar -jar <jar-file.jar>
.
But what happens if this path varies?
The problem is depending on the system it is running, and using maven (pom.xml) to get the artifact, how do we enable opentelemetry with applicationinsights-agent-3.2.11.jar since the location Maven stores the artifact changes from user accounts and computer?
Additionally, how do I specify a relative path to applicationinsights.json file for configuration (as Azure looks for this file inside the applicationinsights-agent-3.2.11.jar directory)?
UPDATE Regarding suggestions, How to define a relative path in java and this other suggested question I am not looking to read files from relative paths. The spring boot application needs to be invoked with a specific argument where it needs to be made aware of the location where maven downloads the the appinsights jar file. Then when the app starts, the appinsights autoconfigure based on applicationinsights.json file, which once again, may vary by location.
Upvotes: 0
Views: 1039
Reputation: 181
Note that the latest applicationinsights-agent*.jar
is available through GitHub and not through Maven repository. Therefore, I don't think that it can be downloaded as dependency to the project using the pom.xml
Now, the question here is not specific to ApplicationInsights agent, but for any java agent used for monitoring. The -javaagent
parameter is supplied to JVM (java
commandline) along with the path. Therefore, it will have to be supplied when JVM starts. How it is being setup would depend on the Server (or the standalone application) being used and its starting mechanism. One such solution is discussed here: How to attach a java agent on to a running spring-boot application. As there are many ways that the application can be deployed/run, the relative path would vary based on it.
If you are running standlone springboot application, you may also modify the mvnw
or mvnw.cmd
scripts to include %MAVEN_OPTS%
with the -javaagent=agent path
, where path could be relative to one of the variables defined in it, like %MAVEN_PROJECTBASEDIR%
Regarding the applicationinsights.json
file, you can either have it in the same directory as the agent jar, OR set up environment variables to get the settings from there (instead of having the json file). You may refer to this link for details on available Environment variables to configure the agent. These environment variables can be set based on how/where the application is being deployed/run before the JVM initializes to make it available to javaagent.
Upvotes: 0