title: Application Insights for Java web apps that are already live description: Start monitoring a web application that is already running on your server services: application-insights documentationcenter: java author: harelbr manager: carmonm
ms.assetid: 12f3dbb9-915f-4087-87c9-807286030b0b ms.service: application-insights ms.workload: tbd ms.tgt_pltfrm: ibiza ms.devlang: na ms.topic: article ms.date: 11/10/2016 ms.author: mbullwin
If you have a web application that is already running on your J2EE server, you can start monitoring it with Application Insights without the need to make code changes or recompile your project. With this option, you get information about HTTP requests sent to your server, unhandled exceptions, and performance counters.
You'll need a subscription to Microsoft Azure.
Note
The procedure on this page adds the SDK to your web app at runtime. This runtime instrumentation is useful if you don't want to update or rebuild your source code. But if you can, we recommend you add the SDK to the source code instead. That gives you more options such as writing code to track user activity.
-
Sign in to the Microsoft Azure portal
-
Create a new Application Insights resource and set the application type to Java web application.
The resource is created in a few seconds.
-
Open the new resource and get its instrumentation key. You'll need to paste this key into your code project shortly.
- Download the Application Insights SDK for Java.
- On your server, extract the SDK contents to the directory from which your project binaries are loaded. If you’re using Tomcat, this directory would typically be under
webapps/<your_app_name>/WEB-INF/lib
Note that you need to repeat this on each server instance, and for each app.
Create ApplicationInsights.xml in the folder in which you added the SDK. Put into it the following XML.
Substitute the instrumentation key that you got from the Azure portal.
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">
<!-- The key from the portal: -->
<InstrumentationKey>** Your instrumentation key **</InstrumentationKey>
<!-- HTTP request component (not required for bare API) -->
<TelemetryModules>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule"/>
</TelemetryModules>
<!-- Events correlation (not required for bare API) -->
<!-- These initializers add context data to each event -->
<TelemetryInitializers>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationIdTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationNameTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebSessionTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserAgentTelemetryInitializer"/>
</TelemetryInitializers>
</ApplicationInsights>
- The instrumentation key is sent along with every item of telemetry and tells Application Insights to display it in your resource.
- The HTTP Request component is optional. It automatically sends telemetry about requests and response times to the portal.
- Events correlation is an addition to the HTTP request component. It assigns an identifier to each request received by the server, and adds this identifier as a property to every item of telemetry as the property 'Operation.Id'. It allows you to correlate the telemetry associated with each request by setting a filter in diagnostic search.
Locate and open the web.xml file in your project, and merge the following snippet of code under the web-app node, where your application filters are configured.
To get the most accurate results, the filter should be mapped before all other filters.
<filter>
<filter-name>ApplicationInsightsWebFilter</filter-name>
<filter-class>
com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>ApplicationInsightsWebFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
You might need to set exceptions to send outgoing data.
Return to your Application Insights resource in Microsoft Azure portal.
Telemetry about HTTP requests appears on the overview blade. (If it isn't there, wait a few seconds and then click Refresh.)
Click through any chart to see more detailed metrics.
And when viewing the properties of a request, you can see the telemetry events associated with it such as requests and exceptions.
- Add telemetry to your web pages to monitor page views and user metrics.
- Set up web tests to make sure your application stays live and responsive.
- Capture log traces
- Search events and logs to help diagnose problems.