You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Dependency Tracking in Azure Application Insights | Microsoft Docs
3
-
description: Analyze usage, availability, and performance of your on-premises or Microsoft Azure web application with Application Insights.
3
+
description: Monitor dependency calls from your on-premises or Microsoft Azure web application with Application Insights.
4
4
services: application-insights
5
5
documentationcenter: .net
6
6
author: mrbullwinkle
@@ -15,73 +15,185 @@ ms.date: 12/06/2018
15
15
ms.author: mbullwin
16
16
17
17
---
18
-
# Set up Application Insights: Dependency tracking
19
-
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](../../azure-monitor/app/app-insights-overview.md) 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.
18
+
# Dependency Tracking in Azure Application Insights
20
19
21
-
The out-of-the-box dependency monitor currently reports calls to these types of dependencies:
20
+
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](../../azure-monitor/app/app-insights-overview.md) 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.
22
21
23
-
* Server
24
-
* SQL databases
25
-
* ASP.NET web and WCF services that use HTTP-based bindings
26
-
* Local or remote HTTP calls
27
-
* Azure Cosmos DB, table, blob storage, and queue
28
-
* Web pages
29
-
* AJAX calls
22
+
## Automatically tracked dependencies
30
23
31
-
Monitoring works by using [byte code instrumentation](https://msdn.microsoft.com/library/z9z62c29.aspx) around select methods or based on DiagnosticSource callbacks (in the latest .NET SDKs) from the .NET Framework. Performance overhead is minimal.
24
+
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](https://docs.microsoft.com/azure/azure-monitor/app/asp-net) and [ASP.NET Core](https://docs.microsoft.com/azure/azure-monitor/app/asp-net-core) applications, when configured as per the linked official docs. `DependencyTrackingTelemetryModule` is shipped as [this](https://www.nuget.org/packages/Microsoft.ApplicationInsights.DependencyCollector/) NuGet package, and is brought automatically when using either of the NuGet packages `Microsoft.ApplicationInsights.Web` or `Microsoft.ApplicationInsights.AspNetCore`.
32
25
33
-
You can also write your own SDK calls to monitor other dependencies, both in the client and server code, using the [TrackDependency API](../../azure-monitor/app/api-custom-events-metrics.md#trackdependency).
26
+
`DependencyTrackingTelemetryModule` currently tracks the following dependencies automatically:
34
27
35
-
> [!NOTE]
36
-
> Azure Cosmos DB is tracked automatically only if [HTTP/HTTPS](../../cosmos-db/performance-tips.md#networking) is used. TCP mode won't be captured by Application Insights.
28
+
|Dependencies |Details|
29
+
|---------------|-------|
30
+
|Http/Https | Local or Remote http/https calls |
31
+
|WCF calls| Only tracked automatically if Http-based bindings are used.|
32
+
|SQL | Calls made with `SqlClient`. See [this](##advanced-sql-tracking-to-get-full-sql-query) for capturing SQL query . |
33
+
|[Azure storage (Blob, Table, Queue )](https://www.nuget.org/packages/WindowsAzure.Storage/)| Calls made with Azure Storage Client. |
34
+
|[EventHub Client SDK](https://www.nuget.org/packages/Microsoft.Azure.EventHubs)| Version 1.1.0 and above. |
35
+
|[ServiceBus Client SDK](https://www.nuget.org/packages/Microsoft.Azure.ServiceBus)| Version 3.0.0 and above. |
36
+
|Azure Cosmos DB | Only tracked automatically if HTTP/HTTPS is used. TCP mode won't be captured by Application Insights. |
37
37
38
-
## Set up dependency monitoring
39
-
Partial dependency information is collected automatically by the [Application Insights SDK](asp-net.md). To get complete data, install the appropriate agent for the host server.
40
38
41
-
| Platform | Install |
39
+
## Setup automatic dependency tracking in Console Apps
40
+
41
+
To automatically track dependencies from .NET/.NET Core console apps, install the Nuget package `Microsoft.ApplicationInsights.DependencyCollector`, and initialize `DependencyTrackingTelemetryModule` as follows:
Dependencies are automatically collected by using one of the following techniques:
51
+
52
+
* Using byte code instrumentation around select methods. (InstrumentationEngine either from StatusMonitor or Azure Web App Extension)
53
+
* EventSource callbacks
54
+
* DiagnosticSource callbacks (in the latest .NET/.NET Core SDKs)
55
+
56
+
## Manually tracking dependencies
57
+
58
+
The following are some examples of dependencies, which aren't automatically collected, and hence require manual tracking.
59
+
60
+
* Azure Cosmos DB is tracked automatically only if [HTTP/HTTPS](../../cosmos-db/performance-tips.md#networking) is used. TCP mode won't be captured by Application Insights.
61
+
* Redis
62
+
63
+
For those dependencies not automatically collected by SDK, you can track them manually using the [TrackDependency API](api-custom-events-metrics.md#trackdependency) that is used by the standard auto collection modules.
64
+
65
+
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`.
Alternatively, `TelemetryClient` provides extension methods `StartOperation` and `StopOperation` which can be used to manually track dependencies, as shown [here](custom-operations-tracking.md#outgoing-dependencies-tracking)
84
+
85
+
If you want to switch off the standard dependency tracking module, remove the reference to DependencyTrackingTelemetryModule in [ApplicationInsights.config](../../azure-monitor/app/configuration-with-applicationinsights-config.md) for ASP.NET applications. For ASP.NET Core applications, follow instructions [here](asp-net-core.md#configuring-or-removing-default-telemetrymodules).
86
+
87
+
## Tracking AJAX calls from Web Pages
88
+
89
+
For web pages, Application Insights JavaScript SDK automatically collects AJAX calls as dependencies as described [here](javascript.md#ajax-performance). This document focuses on dependencies from server components.
90
+
91
+
## Advanced SQL tracking to get full SQL Query
92
+
93
+
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.
94
+
95
+
For ASP.NET Core applications, there's no additional step required to get the full SQL Query.
96
+
97
+
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.
98
+
99
+
| Platform | Step(s) Needed to get full SQL Query |
42
100
| --- | --- |
43
-
| IIS Server |Either [install Status Monitor on your server](../../azure-monitor/app/monitor-performance-live-website-now.md) or [Upgrade your application to .NET framework 4.6 or later](https://go.microsoft.com/fwlink/?LinkId=528259) and install the [Application Insights SDK](asp-net.md) in your app. |
44
-
| Azure Web App |In your web app control panel, [open the Application Insights blade in your web app control panel](../../azure-monitor/app/azure-web-apps.md) and choose Install if prompted. |
45
-
| Azure Cloud Service |[Use startup task](../../azure-monitor/app/cloudservices.md) or [Install .NET framework 4.6+](../../cloud-services/cloud-services-dotnet-install-dotnet.md)|
101
+
| Azure Web App |In your web app control panel, [open the Application Insights blade](../../azure-monitor/app/azure-web-apps.md) and enable SQL Commands under .NET |
102
+
| IIS Server (Azure VM, on-prem, and so on.) | [Install Status Monitor on your server where application is running](../../azure-monitor/app/monitor-performance-live-website-now.md) and restart IIS.
103
+
| Azure Cloud Service |[Use startup task](../../azure-monitor/app/cloudservices.md) to [Install Status Monitor](monitor-performance-live-website-now.md#download)|
104
+
| IIS Express | Not supported
105
+
106
+
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.
46
107
47
108
## Where to find dependency data
109
+
48
110
*[Application Map](#application-map) visualizes dependencies between your app and neighboring components.
49
-
*[Performance, browser, and failure blades](https://docs.microsoft.com/azure/azure-monitor/learn/tutorial-performance) show server dependency data.
111
+
*[Performance, browser, and failure blades](#performance-and-failure-blades) show server dependency data.
50
112
*[Browsers blade](#ajax-calls) shows AJAX calls from your users' browsers.
51
113
* Click through from slow or failed requests to check their dependency calls.
52
114
*[Analytics](#analytics) can be used to query dependency data.
53
115
54
116
## Application Map
117
+
55
118
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.
> **100% failures?** - This probably indicates that you are only getting partial dependency data. You need to [set up dependency monitoring appropriate to your platform](#set-up-dependency-monitoring).
71
-
>
72
-
>
133
+
Click through the summary charts or the table items to search raw occurrences of these calls.
**Failure counts** are shown on the **Failures** blade. A failure is any return code that is not in the range 200-399, or unknown.
73
138
74
139
## AJAX Calls
140
+
75
141
The Browsers blade shows the duration and failure rate of AJAX calls from [JavaScript in your web pages](../../azure-monitor/app/javascript.md). They are shown as Dependencies.
76
142
77
143
## <aname="diagnosis"></a> Diagnose slow requests
78
-
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.
144
+
145
+
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.
146
+
147
+
Let's walk through an example of that.
148
+
149
+
### Tracing from requests to dependencies
150
+
151
+
Open the Performance blade, and look at the grid of requests:
152
+
153
+

154
+
155
+
The top one is taking long. Let's see if we can find out where the time is spent.
156
+
157
+
Click that row to see individual request events:
158
+
159
+

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

164
+
165
+
It looks like most of the time servicing this request was spent in a call to a local service.
166
+
167
+
Select that row to get more information:
168
+
169
+

170
+
171
+
Looks like this dependency 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.
172
+
173
+
### Request timeline
174
+
175
+
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:
176
+
177
+

178
+
179
+
There seems to be a large gap after the first dependency call, so we should look at our code to see why that is.
79
180
80
181
### Profile your live site
81
182
82
-
No idea where the time goes? The [Application Insights profiler](../../azure-monitor/app/profiler.md) traces HTTP calls to your live site and shows which functions in your code took the longest time.
183
+
No idea where the time goes? The [Application Insights profiler](../../azure-monitor/app/profiler.md) traces HTTP calls to your live site and shows you the functions in your code that took the longest time.
184
+
185
+
## Failed requests
186
+
187
+
Failed requests might also be associated with failed calls to dependencies. Again, we can click through to track down the problem.
188
+
189
+

190
+
191
+
Click through to an occurrence of a failed request, and look at its associated events.
192
+
193
+

83
194
84
195
## Analytics
196
+
85
197
You can track dependencies in the [Kusto query language](/azure/kusto/query/). Here are some examples.
86
198
87
199
* Find any failed dependency calls:
@@ -119,49 +231,22 @@ You can track dependencies in the [Kusto query language](/azure/kusto/query/). H
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.
238
+
## Frequently asked questions
126
239
127
-
You can write code that sends dependency information, using the same [TrackDependency API](../../azure-monitor/app/api-custom-events-metrics.md#trackdependency) that is used by the standard modules.
240
+
### *How does automatic dependency collector report failed calls to dependencies?*
128
241
129
-
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`.
242
+
* Failed dependency calls will have 'success' field set to False. `DependencyTrackingTelemetryModule` does not report `ExceptionTelemetry`. The full data model for dependency is described [here](data-model-dependency-telemetry.md).
130
243
131
-
```csharp
244
+
## Open-source SDK
245
+
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](https://github.com/Microsoft/ApplicationInsights-dotnet-server).
If you want to switch off the standard dependency tracking module, remove the reference to DependencyTrackingTelemetryModule in [ApplicationInsights.config](../../azure-monitor/app/configuration-with-applicationinsights-config.md).
149
-
150
-
## Troubleshooting
151
-
*Dependency success flag always shows either true or false.*
152
-
153
-
*SQL query not shown in full.*
154
-
155
-
Consult the table below and insure you have chosen the correct configuration to enable dependency monitoring for your application.
156
-
157
-
| Platform | Install |
158
-
| --- | --- |
159
-
| IIS Server |Either [install Status Monitor on your server](../../azure-monitor/app/monitor-performance-live-website-now.md). Or [Upgrade your application to .NET framework 4.6 or later](https://go.microsoft.com/fwlink/?LinkId=528259) and install the [Application Insights SDK](asp-net.md) in your app. |
160
-
| IIS Express |Use IIS Server instead. |
161
-
| Azure Web App |In your web app control panel, [open the Application Insights blade in your web app control panel](../../azure-monitor/app/azure-web-apps.md) and choose Install if prompted. |
162
-
| Azure Cloud Service |[Use startup task](../../azure-monitor/app/cloudservices.md) or [Install .NET framework 4.6+](../../cloud-services/cloud-services-dotnet-install-dotnet.md). |
0 commit comments