Using Azure Monitor Application Insights with Spring Boot

There are two options for enabling Application Insights Java with Spring Boot: JVM argument and programmatically.

Enabling with JVM argument

Add the JVM arg -javaagent:"path/to/applicationinsights-agent-3.4.13.jar" somewhere before -jar, for example:

java -javaagent:"path/to/applicationinsights-agent-3.4.13.jar" -jar <myapp.jar>

Spring Boot via Docker entry point

If you're using the exec form, add the parameter -javaagent:"path/to/applicationinsights-agent-3.4.13.jar" to the parameter list somewhere before the "-jar" parameter, for example:

ENTRYPOINT ["java", "-javaagent:path/to/applicationinsights-agent-3.4.13.jar", "-jar", "<myapp.jar>"]

If you're using the shell form, add the JVM arg -javaagent:"path/to/applicationinsights-agent-3.4.13.jar" somewhere before -jar, for example:

ENTRYPOINT java -javaagent:"path/to/applicationinsights-agent-3.4.13.jar" -jar <myapp.jar>


See configuration options.

Enabling programmatically

To enable Application Insights Java programmatically, you must add the following dependency:


And invoke the attach() method of the class in the first line of your main() method.


The invocation must be at the beginning of the main method.


JRE is not supported.


The temporary directory of the operating system should be writable.


public class SpringBootApp {

  public static void main(String[] args) {
    ApplicationInsights.attach();, args);


Programmatic enablement supports all the same configuration options as the JVM argument enablement, with the following differences below.

Configuration file location

By default, when enabling Application Insights Java programmatically, the configuration file applicationinsights.json will be read from the classpath (src/main/resources, src/test/resources).

From 3.4.3, you can configure the name of a JSON file in the classpath with the applicationinsights.runtime-attach.configuration.classpath.file system property. For example, with -Dapplicationinsights.runtime-attach.configuration.classpath.file=applicationinsights-dev.json, Application Insights will use applicationinsights-dev.json file for configuration.


Spring's or application.yaml files are not supported as as sources for Application Insights Java configuration.

See configuration file path configuration options to change the location for a file outside the classpath.

Structure of applicationinsights-dev.json


Setting up the configuration file

Open your configuration file (either or application.yaml) in the resources folder. Update the file with the following.

        file: "applicationinsights-dev.json"
-Dapplicationinsights.runtime-attach.configuration.classpath.file = "applicationinsights-dev.json"

Self-diagnostic log file location

By default, when enabling Application Insights Java programmatically, the applicationinsights.log file containing the agent logs will be located in the directory from where the JVM is launched (user directory).

See self-diagnostic configuration options to change this location.