'How to add Azure Monitor OpenTelemetry-based auto-instrumentation to Spring Boot Application?

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)?

If you specify a relative path, it will be resolved relative to the directory where applicationinsights-agent-3.2.11.jar is located.

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source