Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

16 Things Every Developer Needs to Know About Application Insights

DZone's Guide to

16 Things Every Developer Needs to Know About Application Insights

Application Insights supports tracking dependency calls in your code and helps you track what requests do, but it also has some monitoring and alerting limitations.

· Performance Zone
Free Resource

Application Insights is Microsoft’s lightweight application performance monitoring service. I have collected a nice list of things that every developer should know, including tips, key features, and limitations.

1. Make Sure Your App Targets .NET 4.6 and Doesn't Support .NET 2.0 

There are some changes in the 4.6 version of the .NET framework that enable some additional data collection abilities. Be sure to update your app and redeploy it. App Insights will work with 4.5 or newer but 4.6 is preferred.

I know it sounds crazy, but you wouldn’t believe how many people have older apps written in 2.0 that they still have to support and have never been upgraded. App Insights does not support 2.0 and they don’t have any plans to do so.

2. Sensitive Data Isn't Scrubbed From Dynamic SQL Queries

If your code uses dynamic SQL, Application Insights will collect the full query and upload it to Azure. This means if the query contains personal information, credit card numbers, or anything else that could be sensitive, it is getting uploaded from your server to Microsoft.

Another thing to know on this topic: App Insights never collects SQL parameters.

3. Key Limitation: Finding Slow SQL Queries

Application Insights provides reporting down to the server and database name being accessed. There is no way to see how long individual queries take, which are the slowest, or which are called the most often. There is also no way to set up monitoring for a specific SQL query.

To get a list of slow SQL queries, you would need to query SQL Server’s DMVs or use a different APM solution. If you are using SQL Azure, it has some built-in tuning advisor functions.

4. SQL Query Times Aren't Always Correct

Only the amount of time to execute the query on the server is included in the timings. A simple query that selects a lot of data may show that it didn’t take very long at all but may have taken a lot more time to actually download the query results.

Below is a simple example of a screenshot of a query that took 83 milliseconds, but it took another 60 to download and iterate the results. Look for missing gaps of time in your requests. They could be caused by this scenario if they return a lot of data.

Learn more in the article How to measure real world SQL performance for ASP.NET.

5. Azure App Services Require a Site Extension for All Features

You can add Application Insights to your project and deploy it to Azure as an App Service. App Insights will seem to work, but there are some things that don’t work until you install the site extension. You can install it via the Azure Portal. I specifically noticed full SQL queries were not collected without it.

6. View Top Exceptions in Your Application

Application Insights has good reporting to group application exceptions so you can uniquely see which ones are occurring and how often.

application insights exceptions

How to Send Exceptions to App Insights

To ensure that all of your exceptions are collected, you must install their SDK and make some code and config changes.

  1. Modify code to collect unhandled exceptions for MVC, global.asax, etc.
  2. If you use log4net, NLog, etc., you can configure it to send your exceptions.
  3. Manually report exceptions via their SDK if needed.

Limitations and Missing Exceptions Features

App Insights is missing some key features around exceptions. If you are having SQL timeouts, for example, odds are they impact multiple applications. App Insights has no reporting across apps to easily see this.

  • No way to see exceptions across all applications.
  • Some other APM solutions don’t require any code or config changes to collect unhandled exceptions.
  • No way to collect all “first chance” exceptions.

7. Asynchronous HttpClient Calls Are Not Supported

Almost all new ASP.NET development is now done in async and uses the common async/await pattern. Unfortunately, it does not support the recommended way to make HTTP calls with ASP.NET.

 public async Task HttpClientAsync() { log.Debug("Starting HttpClient.GetStringAsync()"); string data; using (HttpClient hc = new HttpClient()) { data = await hc.GetStringAsync("http://microsoft.com"); } log.Debug("Completed HttpClient.GetStringAsync()"); return Request.CreateResponse(HttpStatusCode.OK, data); } 

App Insights does pick up the two logging messages via log4net but doesn’t show anything for dependency calls.

It does see it; it just doesn’t associate it with the ASP.NET web request.

8. Tracking Application Dependencies

App Insights supports tracking dependency calls in your code. Microsoft’s documentation says SQL databases, HTTP calls, and Azure storage libraries are supported. Anything else requires using their SDK to manually track each dependency call.

Limitations

App Insights does not support some other notable key Azure dependencies, including Service Bus and Redis.

Some other APM solutions also support MongoDB, RavenDB, Elasticsearch, Redis, Memcached, AppFabric, MSMQ, NServiceBus, AWS services, and more.

9. View All Details for a Single Web Request (Transaction Trace)

One of the key features to help track down what a request does is seeing the complete picture of logging, dependency calls, and other key events associated with a single web request.

The best way to do this in Application Insights is to click All available telemetry for this operation.

10. How to Identify Why a Request (or Entire App) Is Slow

One suggestion is to customize the chart that you see when filtering for a specific operation by adding the “dependency duration.” This will help you see how that compares to overall server response time.

The built-in map feature can be useful for trying to identify the performance of dependencies. It will tell you the average time and % of failures.

I would also suggest going to “Failures” from the menu to look for dependency failures and exceptions.

One thing that would be nice is a visual way to see how each dependency impacts overall performance. When there is a problem with one it is usually easy to see it spike.

Screenshot from Retrace.

11. Monitoring and Alerts Features and Limitations

Application Insights supports configuring alerts for a lot of different conditions, including alerting on metrics like Server Exceptions, Request Rate, Process CPU, etc.

Monitoring Limitations

  • No way to monitor a specific request (URL/action).
  • No way to monitor a specific SQL query.
  • No way to monitor % of requests having errors.
  • Can only monitor averages.

Alerting Limitations

  • Email or webhooks only.
  • Can use a Logic App to send to SMS, Slack, and others.
  • No built-in concept of alert “escalation.”
  • No concept of alert severity like warning vs. critical.
  • Alerts go to everyone or a hard-coded list of emails. No good way to manage distribution lists unless done outside via email groups.

12. Reporting Across Applications

In Azure Application Insights, each app is more or less a “bucket” that all the diagnostics about each app gets reported to. There is no easy way to see exceptions, slow SQL queries, slow web requests, etc. across all of your apps. The only workaround that can provide some very minimal visibility is making a custom dashboard and selecting some widgets across multiple apps.

13. No Support for the Concept of Multiple Environments

Within an individual application, there is no high-level way to separate out and report data by environment (i.e., Dev, QA, Prod). Microsoft has a couple workarounds that they recommend:

  1. Configure a unique “application” via separate instrumentation keys. This works but then there is no reporting across them. They are completely isolated.
  2. Use a custom field for the environment. You would then need to probably make your own dashboards and widgets in App Insights filtered down by that custom field.

14. App Insights Is Not a Code Profiler

Most application performance management (APM) solutions use code profiling to do data collection. Microsoft Application Insights does not use profiling. Instead, it relies on collecting data via the .NET framework via ETW and other sources.

Because App Insights does not the CLR profiler, it causes a few limitations:

  • Lack of dependency support. The reason it does not support a wide array of third-party dependencies is primarily because they don’t do code profiling that would let them instrument the libraries.
  • No custom profiling. One of the very useful features of APM solutions is being able to profile custom methods in your code to track their usage and performance. App Insights doesn’t support this. You would instead need to use their SDK and modify your code to report it.

Microsoft is working on some profiling features and may offer it in the future.

15. Application Insights Has a Robust API (You'll Likely Need It)

If your boss likes it when you spend all your time instrumenting your apps manually to report performance data, they will love Application Insights. They have a robust API and SDKs for several programming languages (.NET, Java, Node.js) that let you report requests, pages views, dependency calls, trace (log) messages, exceptions, and more via their TelemetryClient.

Microsoft’s own description highlights it as being “extensible” as it relies on a lot of custom SDK usages to get rich data.

Application Insights is an extensible Application Performance Management (APM) service for web developers.

If your app uses ElasticSearch, MongoDB, Redis, or any other dependency and you would like to see show up in Application Insights on Microsoft Azure, you will need to change your code and manually report it.

16. How to Use Application Insights With Windows Services

If you have a Windows Service-type application that you want to track with App Insights, you will have to integrate their API into your app. For every single place you make a database call, you can simply add a couple lines of code to report the query via their SDK.

As an example, check out this article about using Microsoft Azure Worker Roles with Application Insights.

Topics:
application insights ,performance ,azure ,queries ,monitoring ,alerting

Published at DZone with permission of Matt Watson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}