You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Configure Azure Monitor Application Insights for Spring Boot
3
+
description: How to configure Azure Monitor Application Insights for Spring Boot applications
4
+
ms.topic: conceptual
5
+
ms.date: 06/22/2022
6
+
ms.devlang: java
7
+
ms.custom: devx-track-java
8
+
---
9
+
10
+
# Configure Azure Monitor Application Insights for Spring Boot
11
+
12
+
You can enable the Azure Monitor Application Insights agent for Java by adding an argument to the JVM. When you can't do this, you can use a programmatic configuration. We detail these two configurations below.
13
+
14
+
## Addition of a JVM argument
15
+
16
+
### Usual case
17
+
18
+
Add the JVM arg `-javaagent:path/to/applicationinsights-agent-3.3.0.jar` somewhere before `-jar`, for example:
If you're using the *exec* form, add the parameter `"-javaagent:path/to/applicationinsights-agent-3.3.0.jar"` to the parameter list somewhere before the `"-jar"` parameter, for example:
To use the programmatic configuration and attach the Application Insights agent for Java during the application startup, you must add the following dependency.
And invoke the `attach()` method of the `com.microsoft.applicationinsights.attach.ApplicationInsights` class.
50
+
51
+
> [!TIP]
52
+
> ⚠ The invocation must be requested at the beginning of the `main` method.
53
+
54
+
Example:
55
+
56
+
```java
57
+
@SpringBootApplication
58
+
publicclassSpringBootApp {
59
+
60
+
publicstaticvoidmain(String[] args) {
61
+
ApplicationInsights.attach();
62
+
SpringApplication.run(SpringBootApp.class, args);
63
+
}
64
+
}
65
+
```
66
+
67
+
If you want to use a JSON configuration:
68
+
* The `applicationinsights.json` file has to be in the classpath
69
+
* Or you can use an environmental variable or a system property, more in the _Configuration file path_ part on [this page](../app/java-standalone-config.md).
70
+
71
+
72
+
> [!TIP]
73
+
> With a programmatic configuration, the `applicationinsights.log` file containing the agent logs is located in the directory from where the JVM is launched (user directory). This default behavior can be changed (see the _Self-diagnostics_ part of [this page](../app/java-standalone-config.md)).
If you're using the *exec* form, add the parameter `"-javaagent:path/to/applicationinsights-agent-3.3.0.jar"` to the parameter list somewhere before the `"-jar"` parameter, for example:
Read the Spring Boot documentation [here](../app/java-in-process-agent.md).
38
20
39
21
## Tomcat 8 (Linux)
40
22
@@ -112,7 +94,7 @@ Add `-javaagent:path/to/applicationinsights-agent-3.3.0.jar` to the existing `jv
112
94
...
113
95
```
114
96
115
-
If you are running multiple managed servers on a single host, you will need to add `applicationinsights.agent.id` to the `system-properties` for each `server`:
97
+
If you're running multiple managed servers on a single host, you'll need to add `applicationinsights.agent.id` to the `system-properties` for each `server`:
116
98
117
99
```xml
118
100
...
@@ -134,7 +116,7 @@ If you are running multiple managed servers on a single host, you will need to a
134
116
...
135
117
```
136
118
137
-
The specified `applicationinsights.agent.id` value must be unique. It is used to create a subdirectory under the applicationinsights directory, as each JVM process needs its own local applicationinsights config and local applicationinsights log file. Also, if reporting to the central collector, the `applicationinsights.properties` file is shared by the multiple managed servers, and so the specified `applicationinsights.agent.id` is needed to override the `agent.id` setting in that shared file. `applicationinsights.agent.rollup.id` can be similarly specified in the server's `system-properties` if you need to override the `agent.rollup.id` setting per managed server.
119
+
The specified `applicationinsights.agent.id` value must be unique. It's used to create a subdirectory under the application insights directory, as each JVM process needs its own local application insights config and local application insights log file. Also, if reporting to the central collector, the `applicationinsights.properties` file is shared by the multiple managed servers, and so the specified `applicationinsights.agent.id` is needed to override the `agent.id` setting in that shared file. `applicationinsights.agent.rollup.id` can be similarly specified in the server's `system-properties` if you need to override the `agent.rollup.id` setting per managed server.
138
120
139
121
140
122
## Jetty 9
@@ -171,7 +153,7 @@ Go to **servers > WebSphere application servers > Application servers**, choose
171
153
```
172
154
Java and Process Management > Process definition > Java Virtual Machine
173
155
```
174
-
In "Generic JVM arguments" add the following:
156
+
In "Generic JVM arguments" add the following JVM argument:
0 commit comments