Dependency Tracking in Azure Application Insights

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 the duration of dependency calls, whether its failing or not, along with additional information like name of dependency and so on. You can investigate specific dependency calls, and correlate them to requests and exceptions.

Automatically tracked dependencies

Application Insights SDKs for .NET and .NET Core ships with DependencyTrackingTelemetryModule which is a Telemetry Module that automatically collects dependencies. This dependency collection is enabled automatically for ASP.NET and ASP.NET Core applications, when configured as per the linked official docs. DependencyTrackingTelemetryModule is shipped as this NuGet package, and is brought automatically when using either of the NuGet packages Microsoft.ApplicationInsights.Web or Microsoft.ApplicationInsights.AspNetCore.

DependencyTrackingTelemetryModule currently tracks the following dependencies automatically:

Dependencies Details
Http/Https Local or Remote http/https calls
WCF calls Only tracked automatically if Http-based bindings are used.
SQL Calls made with SqlClient. See this for capturing SQL query.
Azure storage (Blob, Table, Queue ) Calls made with Azure Storage Client.
EventHub Client SDK Version 1.1.0 and above.
ServiceBus Client SDK Version 3.0.0 and above.
Azure Cosmos DB Only tracked automatically if HTTP/HTTPS is used. TCP mode won't be captured by Application Insights.

If you're missing a dependency, or using a different SDK make sure it's in the list of auto-collected dependencies. If the dependency isn't auto-collected, you can still track it manually with a track dependency call.

Setup automatic dependency tracking in Console Apps

To automatically track dependencies from .NET/.NET Core console apps, install the Nuget package Microsoft.ApplicationInsights.DependencyCollector, and initialize DependencyTrackingTelemetryModule as follows:

    DependencyTrackingTelemetryModule depModule = new DependencyTrackingTelemetryModule();
    depModule.Initialize(TelemetryConfiguration.Active);

How automatic dependency monitoring works?

Dependencies are automatically collected by using one of the following techniques:

  • Using byte code instrumentation around select methods. (InstrumentationEngine either from StatusMonitor or Azure Web App Extension)
  • EventSource callbacks
  • DiagnosticSource callbacks (in the latest .NET/.NET Core SDKs)

Manually tracking dependencies

The following are some examples of dependencies, which aren't automatically collected, and hence require manual tracking.

  • Azure Cosmos DB is tracked automatically only if HTTP/HTTPS is used. TCP mode won't be captured by Application Insights.
  • Redis

For those dependencies not automatically collected by SDK, you can track them manually using the TrackDependency API that is used by the standard auto collection 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
    {
        // making dependency call
        success = dependency.Call();
    }
    finally
    {
        timer.Stop();
        telemetryClient.TrackDependency("myDependencyType", "myDependencyCall", "myDependencyData",  startTime, timer.Elapsed, success);
    }

Alternatively, TelemetryClient provides extension methods StartOperation and StopOperation which can be used to manually track dependencies, as shown here

If you want to switch off the standard dependency tracking module, remove the reference to DependencyTrackingTelemetryModule in ApplicationInsights.config for ASP.NET applications. For ASP.NET Core applications, follow instructions here.

Tracking AJAX calls from Web Pages

For web pages, Application Insights JavaScript SDK automatically collects AJAX calls as dependencies.

Advanced SQL tracking to get full SQL Query

For SQL calls, the name of the server and database is always collected and stored as name of the collected DependencyTelemetry. There's an additional field called 'data', which can contain the full SQL query text.

For ASP.NET Core applications, there's no additional step required to get the full SQL Query.

For ASP.NET applications, full SQL query is collected with the help of byte code instrumentation, which requires instrumentation engine. Additional platform-specific steps, as described below, are required.

Platform Step(s) Needed to get full SQL Query
Azure Web App In your web app control panel, open the Application Insights blade and enable SQL Commands under .NET
IIS Server (Azure VM, on-prem, and so on.) Use the Status Monitor PowerShell Module to install the Instrumentation Engine and restart IIS.
Azure Cloud Service Add startup task to install StatusMonitor
Your app should be onboarded to ApplicationInsights SDK at build time by installing NuGet packages for ASP.NET or ASP.NET Core applications
IIS Express Not supported

In the above cases, the correct way of validating that instrumentation engine is correctly installed is by validating that the SDK version of collected DependencyTelemetry is 'rddp'. 'rdddsd' or 'rddf' indicates dependencies are collected via DiagnosticSource or EventSource callbacks, and hence full SQL query won't be captured.

Where to find dependency data

  • Application Map visualizes dependencies between your app and neighboring components.
  • Transaction Diagnostics shows unified, correlated server data.
  • Browsers tab shows AJAX calls from your users' browsers.
  • Click through from slow or failed requests to check their dependency calls.
  • Analytics can be used to query dependency data.

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 doing badly, you can find out whether it's because of slow responses from a dependency.

Tracing from requests to dependencies

Open the Performance tab and navigate to the Dependencies tab at the top next to operations.

Click on a Dependency Name under overall. After you select a dependency a graph of that dependency's distribution of durations will show up on the right.

In the performance tab click on the Dependency tab at the top then a Dependency name in the chart

Click on the blue Samples button on the bottom right and then on a sample to see the end-to-end transaction details.

Click on a sample to see the end-to-end transaction details

Profile your live site

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

Failed requests

Failed requests might also be associated with failed calls to dependencies.

We can go to the Failures tab on the left and then click on the dependencies tab at the top.

Click the failed requests chart

Here you will be able to see the failed dependency count. To get more details about a failed occurrence trying clicking on a dependency name in the bottom table. You can click on the blue Dependencies button at the bottom right to get the end-to-end transaction details.

Logs (Analytics)

You can track dependencies in the Kusto 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

Frequently asked questions

How does automatic dependency collector report failed calls to dependencies?

  • Failed dependency calls will have 'success' field set to False. DependencyTrackingTelemetryModule does not report ExceptionTelemetry. The full data model for dependency is described here.

Open-source SDK

Like every Application Insights SDK, dependency collection module is also open-source. Read and contribute to the code, or report issues at the official GitHub repo.

Next steps