Azure Application Insights (Analytics Tool)

Jatin Luthra
8 min readApr 18, 2019

--

Knowing what is happening with your live web-apps can make or break your customer experience.Today we continuously update and deploy our apps which is great but it can sometime result in performance or even functionality regression.We want to proactively detect issues as soon as they occur and fix them before they start affecting our users.Application Insights can help you do that easily for any of your web app or services.In this blog i’ll give you an overview tour of application insights & its core capabilities.We will also discuss how we can detect, triage & diagnose all our real world problems in our web apps.

Why Monitoring is required ?

Traditionally application monitoring has been an after thought. We used to not think about monitoring before issues start popping up! But with the current modern architectures like Microservices or so many multi-tier applications out there, we need to infuse monitoring into our application development life-cycle from the get go, starting from planning, to development, test and release.

That way we can identify issues and optimisations required as part of the pre and post production process and iterate our tuning continuously, and incidentally, that’s what DevOps is all about!

Introduction to Azure Application Insights

Application Insights is an Application Performance Management (APM) service for web developers on multiple platforms. We can use it to monitor our live web application. It will automatically detect performance anomalies. It includes powerful analytics tools to help us diagnose issues and to understand what users actually do with our app. It’s designed to help us continuously improve performance and usability. It has 2 main paths

  1. Telemetry Collector- Monitor each tier of our application & send data to azure application insights portal.

2. Application Insights Portal- The portal is a cloud based service where we can explore or analyse our data in a variety of charts and exploration tools including a power full query language.

Azure Application Insights (Image from MSDN blog)

We install a small instrumentation package in our application, and set up an Application Insights resource in the Microsoft Azure portal. The instrumentation monitors our app and sends telemetry data to the portal. (The application can run anywhere — it doesn’t have to be hosted in Azure.)

We can instrument not only the web service application, but also any background components, and the JavaScript in the web pages themselves.

All these telemetry streams are integrated in the Azure portal, where we can apply powerful analytic and search tools to the raw data.

Impact on our application

The impact on our app’s performance is very small. Tracking calls are non-blocking, and are batched and sent in a separate thread.

What does Application Insights monitor?

Application Insights is aimed at the development team, to help us understand how our app is performing and how it’s being used. It monitors:

  • Request rates, response times, and failure rates — Find out which pages are most popular, at what times of day, and where our users are. See which pages perform best. If response times and failure rates go high when there are more requests, then perhaps we have a resourcing problem.
  • Dependency rates, response times, and failure rates — Find out whether external services are slowing down our application.
  • Exceptions — Analyse the aggregated statistics, or pick specific instances and drill into the stack trace and related requests. Both server and browser exceptions are reported.
  • Page views and load performance — reported by our users’ browsers.
  • AJAX calls from web pages — rates, response times, and failure rates.
  • User and session counts.
  • Performance counters from our Windows or Linux server machines, such as CPU, memory, and network usage.
  • Host diagnostics from Docker or Azure.
  • Diagnostic trace logs from our app — so that we can correlate trace events with requests.
  • Custom events and metrics that we write ourself in the client or server code, to track business events such as items sold or games won.

How does Application Insights makes all of this easier?

We can create very advanced Azure Dashboard with various metrics pinned into it from your Azure Application Insights.

A sample Azure Dashboard with various Azure App Insight metrics (Image Source Google)

Such a dashboard can help us detect and discover issues that impacts our production environment as well as subsequently our customers. Now we are targeting engineering teams rather than IT ops team so see how engineering teams can benefit from this, developers should have monitoring and diagnostics capabilities as they are building their apps and services.

How to Implement Application Insights for your Java Application ?

Explore Java trace logs in Application Insights

If you’re using Logback or Log4J (v1.2 or v2.0) for tracing, you can have your trace logs sent automatically to Application Insights where you can explore and search on them.

  • Install the Java SDK

1- Get an Application Insights Instrumentation Key ( Sign to azure portal , create an application insight resource by setting application type to be java web application & find the instrumentation key of the new resource)

Image Source MSDN Blog

2-Add the Application Insight SDK for java to your project

If your project is already set up to use Maven for build, merge the following code to your pom.xml file.Then, refresh the project dependencies to get the binaries downloaded.

  • Add logging libraries to your project

1-There are 3 types of logging libraries available for us to send the logs to application insights , we will be going to use Logback as a maven dependency.

logback maven dependency

2-Adding the appender to your logging framework

To start getting traces, merge the relevant snippet of code to the Logback configuration file:

logback appender

For other libraries & build tools please refer to below document from Microsoft..

Where do I see my telemetry?

There are plenty of ways to explore the data but lets discuss the 2 most important aspects of azure application insights :

1- Using Search in the Application Insights- Search is a feature of Application Insights that we use to find and explore individual telemetry items, such as page views, exceptions, or web requests. And we can view log traces and events that we have coded.

A sample search dashboard from App Insights

The main body of Diagnostic Search is a list of telemetry items — server requests, page views, custom events that we have coded, and so on. At the top of the list is a summary chart showing counts of events over time.

Click Refresh to get new events.

Inspect individual items

Select any telemetry item to see key fields and related items.

A Sample Telemetry item

This will launch the end-to-end transaction details view:

End-to-end transaction details

Filter event types

We can filter the events as well based upon event types and deep dive more into those events based upon their property values.

A Sample Exception Event based upon property value(java.net.UnknownHostException)

The event types are:

  • Trace — Diagnostic logs including TrackTrace, log4Net, and System.Diagnostic.Trace calls.
  • Request — HTTP requests received by your server application, including pages, scripts, images, style files, and data. These events are used to create the request and response overview charts.
  • Page View — Telemetry sent by the web client, used to create page view reports.
  • Custom Event — If we inserted calls to TrackEvent() in order to monitor usage, we can search them here.
  • Exception — Uncaught exceptions in the server, and those that we log by using TrackException().
  • Dependency — Calls from our server application to other services such as REST APIs or databases, and AJAX calls from your client code.
  • Availability — Results of availability tests.

Search the data

We can search for terms in any of the property values. This is particularly useful if we have written custom events with property values.

We might want to set a time range, as searches over a shorter range are faster.

A Search capability for custom events(Image source MSDN blog)

2- Using Analytics in the Application Insights- Analytics is the powerful search and query tool of Application Insights. Analytics is a web tool so no setup is required. If you’ve already configured Application Insights for one of your apps then you can analyse your app’s data by opening Analytics from your app’s overview blade.

Application Insights Analytics

Query Data in Analytics

A typical query starts with a table name followed by a series of operators separated by |. For example, let's find out how many records our applications is processing at a time.

A basic query in application Insights

Here Union is the combination of all the tables , be it a Exception, Request, Trace or Page View i.e our application is sending around 22k records at a time to application insights.Lets do a little bit more analytics on our application.For example, lets find out the traffic of last three days coming from which city & render it to pie chart.

Rendering Records on Pie Chart

The language has many attractive features:

  • Filter your raw app telemetry by any fields, including your custom properties and metrics.
  • Join multiple tables — correlate requests with page views, dependency calls, exceptions and log traces.
  • Powerful statistical aggregations.
  • Immediate and powerful visualisations.

Conclusion

So there are other telemetry services as well in application insights which will make it a must use product if you want to proactively monitor your application.This will help you to prevent any major issues happening in your production environment & you can give a wonderful customer experience to your customers by analysing their data.It will also help product managers or product owners who will get that useful telemetry while they are working on their feature prioritisation & they can see the usage of their application and they can also discover what their most popular pages are.So thats a quick wrap about azure application insights !!!

--

--