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
Copy file name to clipboardExpand all lines: articles/azure-monitor/app/java-spring-boot.md
+37-14Lines changed: 37 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,13 +7,11 @@ ms.devlang: java
7
7
ms.custom: devx-track-java
8
8
---
9
9
10
-
# Configure Azure Monitor Application Insights for Spring Boot
10
+
# Using Azure Monitor Application Insights with Spring Boot
11
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.
12
+
There are two options for enabling Application Insights Java with Spring Boot: JVM argument and programmatically.
13
13
14
-
## Addition of a JVM argument
15
-
16
-
### Usual case
14
+
## Enabling with JVM argument
17
15
18
16
Add the JVM arg `-javaagent:"path/to/applicationinsights-agent-3.4.1.jar"` somewhere before `-jar`, for example:
19
17
@@ -35,9 +33,14 @@ If you're using the *shell* form, add the JVM arg `-javaagent:"path/to/applicati
See [configuration options](./java-standalone-config.md).
39
+
40
+
## Enabling programmatically
41
+
42
+
To enable Application Insights Java programmatically, you must add the following dependency:
39
43
40
-
To use the programmatic configuration and attach the Application Insights agent for Java during the application startup, you must add the following dependency.
41
44
```xml
42
45
<dependency>
43
46
<groupId>com.microsoft.azure</groupId>
@@ -46,7 +49,8 @@ To use the programmatic configuration and attach the Application Insights agent
46
49
</dependency>
47
50
```
48
51
49
-
And invoke the `attach()` method of the `com.microsoft.applicationinsights.attach.ApplicationInsights` class.
52
+
And invoke the `attach()` method of the `com.microsoft.applicationinsights.attach.ApplicationInsights` class
53
+
in the first line of your `main()` method.
50
54
51
55
> [!WARNING]
52
56
>
@@ -58,7 +62,7 @@ And invoke the `attach()` method of the `com.microsoft.applicationinsights.attac
58
62
59
63
> [!WARNING]
60
64
>
61
-
> The invocation must be requested at the beginning of the `main` method.
65
+
> The invocation must be at the beginning of the `main` method.
62
66
63
67
Example:
64
68
@@ -73,10 +77,29 @@ public class SpringBootApp {
73
77
}
74
78
```
75
79
76
-
If you want to use a JSON configuration:
77
-
* The `applicationinsights.json` file has to be in the classpath
78
-
* 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). Spring properties defined in a Spring _.properties_ file are not supported.
80
+
### Configuration
81
+
82
+
> [!NOTE]
83
+
> Spring's `application.properties` or `application.yaml` files are not supported as
84
+
> as sources for Application Insights Java configuration.
85
+
86
+
Programmatic enablement supports all the same [configuration options](./java-standalone-config.md)
87
+
as the JVM argument enablement, with the following differences:
88
+
89
+
By default, the configuration file `applicationinsights.json` is read from the classpath.
90
+
91
+
You can also place the `applicationinsights.json` outside of your spring boot jar and specify
92
+
the file path using either
93
+
94
+
*`APPLICATIONINSIGHTS_CONFIGURATION_FILE` environment variable, or
95
+
*`applicationinsights.configuration.file` Java system property
96
+
97
+
If you specify a relative path, it will be resolved relative to the directory from where the JVM is launched (user directory).
98
+
99
+
### Self-diagnostics
79
100
101
+
By default, the `applicationinsights.log` file containing the agent logs is located in the directory
102
+
from where the JVM is launched (user directory).
80
103
81
-
> [!TIP]
82
-
> 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)).
104
+
See [self-diagnostic configuration options](./java-standalone-config.md#self-diagnostics)
105
+
for how to change this location and other self-diagnostics configuration options.
0 commit comments