Set up Application Insights: Dependency tracking

A dependency is an external component that is called by your app. It's typically a service called using HTTP, or a database, or a file system. Application Insights measures how long your application waits for dependencies and how often a dependency call fails. You can investigate specific calls, and relate them to requests and exceptions.

sample charts

The out-of-the-box dependency monitor currently reports calls to these types of dependencies:

  • Server
    • SQL databases
    • ASP.NET web and WCF services that use HTTP-based bindings
    • Local or remote HTTP calls
    • Azure Cosmos DB, table, blob storage, and queue
  • Web pages
    • AJAX calls

Monitoring works by using byte code instrumentation around selected methods. Performance overhead is minimal.

You can also write your own SDK calls to monitor other dependencies, both in the client and server code, using the TrackDependency API.

Set up dependency monitoring

Partial dependency information is collected automatically by the Application Insights SDK. To get complete data, install the appropriate agent for the host server.

Platform Install
IIS Server Either install Status Monitor on your server or Upgrade your application to .NET framework 4.6 or later and install the Application Insights SDK in your app.
Azure Web App In your web app control panel, open the Application Insights blade in your web app control panel and choose Install if prompted.
Azure Cloud Service Use startup task or Install .NET framework 4.6+

Where to find dependency data

Application Map

Application Map acts as a visual aid to discovering dependencies between the components of your application. It is automatically generated from the telemetry from your app. This example shows AJAX calls from the browser scripts and REST calls from the server app to two external services.

Application Map

  • Navigate from the boxes to relevant dependency and other charts.
  • Pin the map to the dashboard, where it will be fully functional.

Learn more.

Performance and failure blades

The performance blade shows the duration of dependency calls made by the server app. There's a summary chart and a table segmented by call.

Performance blade dependency charts

Click through the summary charts or the table items to search raw occurrences of these calls.

Dependency call instances

Failure counts are shown on the Failures blade. A failure is any return code that is not in the range 200-399, or unknown.

Note

100% failures? - This probably indicates that you are only getting partial dependency data. You need to set up dependency monitoring appropriate to your platform.

AJAX Calls

The Browsers blade shows the duration and failure rate of AJAX calls from JavaScript in your web pages. They are shown as Dependencies.

Diagnose slow requests

Each request event is associated with the dependency calls, exceptions and other events that are tracked while your app is processing the request. So if some requests are performing badly, you can find out whether it's due to slow responses from a dependency.

Let's walk through an example of that.

Tracing from requests to dependencies

Open the Performance blade, and look at the grid of requests:

List of requests with averages and counts

The top one is taking very long. Let's see if we can find out where the time is spent.

Click that row to see individual request events:

List of request occurrences

Click any long-running instance to inspect it further, and scroll down to the remote dependency calls related to this request:

Find Calls to Remote Dependencies, identify unusual Duration

It looks like most of the time servicing this request was spent in a call to a local service.

Select that row to get more information:

Click through that remote dependency to identify the culprit

Looks like this is where the problem is. We've pinpointed the problem, so now we just need to find out why that call is taking so long.

Request timeline

In a different case, there is no dependency call that is particularly long. But by switching to the timeline view, we can see where the delay occurred in our internal processing:

Find Calls to Remote Dependencies, identify unusual Duration

There seems to be a big gap after the first dependency call, so we should look at our code to see why that is.

Profile your live site

No idea where the time goes? The Application Insights profiler traces HTTP calls to your live site and shows you which functions in your code took the longest time.

Failed requests

Failed requests might also be associated with failed calls to dependencies. Again, we can click through to track down the problem.

Click the failed requests chart

Click through to an occurrence of a failed request, and look at its associated events.

Click a request type, click the instance to get to a different view of the same instance, click it to get exception details.

Analytics

You can track dependencies in the Analytics query language. Here are some examples.

  • Find any failed dependency calls:

    dependencies | where success != "True" | take 10
  • Find AJAX calls:

    dependencies | where client_Type == "Browser" | take 10
  • Find dependency calls associated with requests:

    dependencies
    | where timestamp > ago(1d) and  client_Type != "Browser"
    | join (requests | where timestamp > ago(1d))
      on operation_Id  
  • Find AJAX calls associated with page views:

    dependencies
    | where timestamp > ago(1d) and  client_Type == "Browser"
    | join (browserTimings | where timestamp > ago(1d))
      on operation_Id

Custom dependency tracking

The standard dependency-tracking module automatically discovers external dependencies such as databases and REST APIs. But you might want some additional components to be treated in the same way.

You can write code that sends dependency information, using the same TrackDependency API that is used by the standard modules.

For example, if you build your code with an assembly that you didn't write yourself, you could time all the calls to it, to find out what contribution it makes to your response times. To have this data displayed in the dependency charts in Application Insights, send it using TrackDependency.


            var startTime = DateTime.UtcNow;
            var timer = System.Diagnostics.Stopwatch.StartNew();
            try
            {
                success = dependency.Call();
            }
            finally
            {
                timer.Stop();
                telemetry.TrackDependency("myDependency", "myCall", startTime, timer.Elapsed, success);
            }

If you want to switch off the standard dependency tracking module, remove the reference to DependencyTrackingTelemetryModule in ApplicationInsights.config.

Troubleshooting

Dependency success flag always shows either true or false.

SQL query not shown in full.

  • Upgrade to the latest version of the SDK. If your .NET version is less than 4.6:
    • IIS host: Install Application Insights Agent on the host servers.
    • Azure web app: Open Application Insights tab in the web app control panel, and install Application Insights.

Video

Next steps