Skip to content

Commit c707527

Browse files
authored
Merge pull request #89275 from trask/application-insights-java-2.5.0
Update ApplicationInsights Java to 2.5.0
2 parents 99edd52 + 9d45dcb commit c707527

10 files changed

+181
-1222
lines changed

.openpublishing.redirection.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41766,6 +41766,26 @@
4176641766
"redirect_url": "/azure/azure-monitor/app/java-get-started",
4176741767
"redirect_document_id": false
4176841768
},
41769+
{
41770+
"source_path": "articles/azure-monitor/app/java-get-started-25-beta.md",
41771+
"redirect_url": "/azure/azure-monitor/app/java-get-started",
41772+
"redirect_document_id": false
41773+
},
41774+
{
41775+
"source_path": "articles/azure-monitor/app/java-trace-logs-25-beta.md",
41776+
"redirect_url": "/azure/azure-monitor/app/java-trace-logs",
41777+
"redirect_document_id": false
41778+
},
41779+
{
41780+
"source_path": "articles/azure-monitor/app/java-agent-25-beta.md",
41781+
"redirect_url": "/azure/azure-monitor/app/java-agent",
41782+
"redirect_document_id": false
41783+
},
41784+
{
41785+
"source_path": "articles/azure-monitor/app/micrometer-java-25-beta.md",
41786+
"redirect_url": "/azure/azure-monitor/app/micrometer-java",
41787+
"redirect_document_id": false
41788+
},
4176941789
{
4177041790
"source_path": "articles/cognitive-services/Translator/quickstart-csharp-translate.md",
4177141791
"redirect_url": "/azure/cognitive-services/Translator/quickstart-translate",

articles/azure-monitor/app/java-agent-25-beta.md

Lines changed: 0 additions & 142 deletions
This file was deleted.

articles/azure-monitor/app/java-agent.md

Lines changed: 45 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,32 @@ ms.topic: conceptual
1313
ms.date: 01/10/2019
1414
ms.author: mbullwin
1515
---
16-
# Monitor dependencies, caught exceptions and method execution times in Java web apps
16+
# Monitor dependencies, caught exceptions, and method execution times in Java web apps
1717

1818

1919
If you have [instrumented your Java web app with Application Insights][java], you can use the Java Agent to get deeper insights, without any code changes:
2020

2121
* **Dependencies:** Data about calls that your application makes to other components, including:
22-
* **REST calls** made via HttpClient, OkHttp, and RestTemplate (Spring) are captured.
23-
* **Redis** calls made via the Jedis client are captured.
24-
* **[JDBC calls](https://docs.oracle.com/javase/7/docs/technotes/guides/jdbc/)** - MySQL, SQL Server and Oracle DB commands are automatically captured. For MySQL, if the call takes longer than 10s, the agent reports the query plan.
25-
* **Caught exceptions:** Information about exceptions that are handled by your code.
26-
* **Method execution time:** Information about the time it takes to execute specific methods.
22+
* **Outgoing HTTP calls** made via Apache HttpClient, OkHttp, and `java.net.HttpURLConnection` are captured.
23+
* **Redis calls** made via the Jedis client are captured.
24+
* **JDBC queries** - For MySQL and PostgreSQL, if the call takes longer than 10 seconds, the agent reports the query plan.
25+
26+
* **Application logging:** Capture and correlate your application logs with HTTP requests and other telemetry
27+
* **Log4j 1.2**
28+
* **Log4j2**
29+
* **Logback**
30+
31+
* **Better operation naming:** (used for aggregation of requests in the portal)
32+
* **Spring** - based on `@RequestMapping`.
33+
* **JAX-RS** - based on `@Path`.
2734

2835
To use the Java agent, you install it on your server. Your web apps must be instrumented with the [Application Insights Java SDK][java].
2936

3037
## Install the Application Insights agent for Java
3138
1. On the machine running your Java server, [download the agent](https://github.com/Microsoft/ApplicationInsights-Java/releases/latest). Please ensure to download the same version of Java Agent as Application Insights Java SDK core and web packages.
32-
2. Edit the application server startup script, and add the following JVM:
39+
2. Edit the application server startup script, and add the following JVM arg:
3340

34-
`javaagent:`*full path to the agent JAR file*
41+
`-javaagent:<full path to the agent JAR file>`
3542

3643
For example, in Tomcat on a Linux machine:
3744

@@ -44,58 +51,46 @@ Create a file named `AI-Agent.xml` and place it in the same folder as the agent
4451
Set the content of the xml file. Edit the following example to include or omit the features you want.
4552

4653
```XML
54+
<?xml version="1.0" encoding="utf-8"?>
55+
<ApplicationInsightsAgent>
56+
<Instrumentation>
57+
<BuiltIn enabled="true">
4758

48-
<?xml version="1.0" encoding="utf-8"?>
49-
<ApplicationInsightsAgent>
50-
<Instrumentation>
51-
52-
<!-- Collect remote dependency data -->
53-
<BuiltIn enabled="true">
54-
<!-- Disable Redis or alter threshold call duration above which arguments are sent.
55-
Defaults: enabled, 10000 ms -->
56-
<Jedis enabled="true" thresholdInMS="1000"/>
57-
58-
<!-- Set SQL query duration above which query plan is reported (MySQL, PostgreSQL). Default is 10000 ms. -->
59-
<MaxStatementQueryLimitInMS>1000</MaxStatementQueryLimitInMS>
60-
</BuiltIn>
61-
62-
<!-- Collect data about caught exceptions
63-
and method execution times -->
64-
65-
<Class name="com.myCompany.MyClass">
66-
<Method name="methodOne"
67-
reportCaughtExceptions="true"
68-
reportExecutionTime="true"
69-
/>
70-
<!-- Report on the particular signature
71-
void methodTwo(String, int) -->
72-
<Method name="methodTwo"
73-
reportExecutionTime="true"
74-
signature="(Ljava/lang/String;I)V" />
75-
</Class>
76-
77-
</Instrumentation>
78-
</ApplicationInsightsAgent>
59+
<!-- capture logging via Log4j 1.2, Log4j2, and Logback, default is true -->
60+
<Logging enabled="true" />
7961

80-
```
62+
<!-- capture outgoing HTTP calls performed through Apache HttpClient, OkHttp,
63+
and java.net.HttpURLConnection, default is true -->
64+
<HTTP enabled="true" />
8165

82-
You have to enable reports exception and method timing for individual methods.
66+
<!-- capture JDBC queries, default is true -->
67+
<JDBC enabled="true" />
8368

84-
By default, `reportExecutionTime` is true and `reportCaughtExceptions` is false.
69+
<!-- capture Redis calls, default is true -->
70+
<Jedis enabled="true" />
71+
72+
<!-- capture query plans for JDBC queries that exceed this value (MySQL, PostgreSQL),
73+
default is 10000 milliseconds -->
74+
<MaxStatementQueryLimitInMS>1000</MaxStatementQueryLimitInMS>
75+
76+
</BuiltIn>
77+
</Instrumentation>
78+
</ApplicationInsightsAgent>
79+
```
8580

8681
## Additional config (Spring Boot)
8782

8883
`java -javaagent:/path/to/agent.jar -jar path/to/TestApp.jar`
8984

90-
For Azure App Services do the following:
85+
For Azure App Services, do the following:
9186

9287
* Select Settings > Application Settings
9388
* Under App Settings, add a new key value pair:
9489

9590
Key: `JAVA_OPTS`
96-
Value: `-javaagent:D:/home/site/wwwroot/applicationinsights-agent-2.3.1-SNAPSHOT.jar`
91+
Value: `-javaagent:D:/home/site/wwwroot/applicationinsights-agent-2.5.0.jar`
9792

98-
For the latest version of the Java agent check the releases [here](https://github.com/Microsoft/ApplicationInsights-Java/releases
93+
For the latest version of the Java agent, check the releases [here](https://github.com/Microsoft/ApplicationInsights-Java/releases
9994
).
10095

10196
The agent must be packaged as a resource in your project such that it ends up in the D:/home/site/wwwroot/ directory. You can confirm that your agent is in the correct App Service directory by going to **Development Tools** > **Advanced Tools** > **Debug Console** and examining the contents of the site directory.
@@ -105,33 +100,16 @@ The agent must be packaged as a resource in your project such that it ends up in
105100
> [!NOTE]
106101
> AI-Agent.xml and the agent jar file should be in the same folder. They are often placed together in the `/resources` folder of the project.
107102
108-
### Spring Rest Template
109-
110-
In order for Application Insights to successfully instrument HTTP calls made with Spring's Rest Template, use of the Apache HTTP Client is required. By default Spring's Rest Template is not configured to use the Apache HTTP Client. By specifying [HttpComponentsClientHttpRequestfactory](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.html) in the constructor of a Spring Rest Template, it will use Apache HTTP.
111-
112-
Here's an example of how to do this with Spring Beans. This is a very simple example which uses the default settings of the factory class.
113-
114-
```java
115-
@bean
116-
public ClientHttpRequestFactory httpRequestFactory() {
117-
return new HttpComponentsClientHttpRequestFactory()
118-
}
119-
@Bean(name = 'myRestTemplate')
120-
public RestTemplate dcrAccessRestTemplate() {
121-
return new RestTemplate(httpRequestFactory())
122-
}
123-
```
124-
125103
#### Enable W3C distributed tracing
126104

127105
Add the following to AI-Agent.xml:
128106

129107
```xml
130108
<Instrumentation>
131-
<BuiltIn enabled="true">
132-
<HTTP enabled="true" W3C="true" enableW3CBackCompat="true"/>
133-
</BuiltIn>
134-
</Instrumentation>
109+
<BuiltIn enabled="true">
110+
<HTTP enabled="true" W3C="true" enableW3CBackCompat="true"/>
111+
</BuiltIn>
112+
</Instrumentation>
135113
```
136114

137115
> [!NOTE]
@@ -142,7 +120,7 @@ Ideally this would be the case when all your services have been updated to newer
142120
Make sure that **both [incoming](correlation.md#w3c-distributed-tracing) and outgoing (agent) configurations** are exactly same.
143121

144122
## View the data
145-
In the Application Insights resource, aggregated remote dependency and method execution times appears [under the Performance tile][metrics].
123+
In the Application Insights resource, aggregated remote dependency and method execution times appear [under the Performance tile][metrics].
146124

147125
To search for individual instances of dependency, exception, and method reports, open [Search][diagnostic].
148126

0 commit comments

Comments
 (0)