Monitor dependencies, caught exceptions and method execution times in Java web apps

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

  • Dependencies: Data about calls that your application makes to other components, including:
    • REST calls made via HttpClient, OkHttp, and RestTemplate (Spring) are captured.
    • Redis calls made via the Jedis client are captured.
    • JDBC calls - 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.
  • Caught exceptions: Information about exceptions that are handled by your code.
  • Method execution time: Information about the time it takes to execute specific methods.

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

Install the Application Insights agent for Java

  1. On the machine running your Java server, download the agent. Please ensure to download the same verson of Java Agent as Application Insights Java SDK core and web packages.
  2. Edit the application server startup script, and add the following JVM:

    javaagent:full path to the agent JAR file

    For example, in Tomcat on a Linux machine:

    export JAVA_OPTS="$JAVA_OPTS -javaagent:<full path to agent JAR file>"

  3. Restart your application server.

Configure the agent

Create a file named AI-Agent.xml and place it in the same folder as the agent JAR file.

Set the content of the xml file. Edit the following example to include or omit the features you want.

    <?xml version="1.0" encoding="utf-8"?>

        <!-- Collect remote dependency data -->
        <BuiltIn enabled="true">
           <!-- Disable Redis or alter threshold call duration above which arguments are sent.
               Defaults: enabled, 10000 ms -->
           <Jedis enabled="true" thresholdInMS="1000"/>

           <!-- Set SQL query duration above which query plan is reported (MySQL, PostgreSQL). Default is 10000 ms. -->

        <!-- Collect data about caught exceptions
             and method execution times -->

        <Class name="com.myCompany.MyClass">
           <Method name="methodOne"

           <!-- Report on the particular signature
                void methodTwo(String, int) -->
           <Method name="methodTwo"
              signature="(Ljava/lang/String;I)V" />


You have to enable reports exception and method timing for individual methods.

By default, reportExecutionTime is true and reportCaughtExceptions is false.

View the data

In the Application Insights resource, aggregated remote dependency and method execution times appears under the Performance tile.

To search for individual instances of dependency, exception, and method reports, open Search.

Diagnosing dependency issues - learn more.

Questions? Problems?