Stefano Tommesani

  • Increase font size
  • Default font size
  • Decrease font size
Home

Say goodbye to "it does not happen on my PC!" with Azure

AzureLogoIt is not easy to monitor how our code behaves on a vast array of different machines. A myriad of different configurations can lead to errors that are difficult to reproduce and even more difficult to anticipate. And when the customer calls complaining about a crash, provided information on what lead to the problem is often incomplete or misleading. Fortunately, remote telemetry of software applications is here to help and is going mainstream even in the desktop area. Let's see how easy it is to monitor a desktop Windows application using the new Azure Application Insights service: this article on the Azure site explains all the necessary steps. Summing up, here is what we need to do:

  1. create an Application Insights resource in the Azure portal
  2. make a copy of the Instrumentation key, as we will need it later in our app
  3. add one of the following NuGet packages: Microsoft.ApplicationInsights.WindowsServer for the full set of functionalities, including performance counter collection and dependency monitoring, or Microsoft.ApplicationInsights that includes the core API only
  4. initialize the TelemetryClient object in your app
  5. set the intrumentation key in the code of the app: TelemetryConfiguration.Active.InstrumentationKey = " your key ";
  6. insert telemetry calls, like TrackPageView, TrackException etc.

For additional reference on these steps, check out the official ApplicationInsights repository on GitHub.

However, before peppering our code with calls to the TelemetryClient like the following ones

  • TrackPageView(pageName) on switching forms, pages, or tabs
  • TrackEvent(eventName) for other user actions
  • TrackMetric(name, value) to send regular reports of metrics not attached to specific events
  • TrackTrace(logEvent) for diagnostic logging
  • TrackException(exception) in catch clauses

let's try to adapt the logging interface we already have in place to also support telemetry data (TrackTrace and TrackException will likely match the Info and Error log levels) and create a new implementation of the logging interface that forwards data to both local log and remote telemetry at the same time with minimal effort. Once the benefits of telemetry are tangible, adding monitoring of users' actions with TrackPage and TrackEvent will be easy to justify.

Once the telemetry integration is done and the software is deployed, we log into the Azure dashboard and open Application Insights for the test app:

AppInsight1

 

Being a demo app, there is not a lot of usage data available, but still the graph on top gives us information on how many users are interacting with our app and how much. What should catch our attention is the number of crashes in the last 24 hours:

 

AppInsight2

 

Luckily crashes are trending down, but still 587 crashes are still way too many, so let's click on Crashes box to gain a greater insight on what is happening:

 

AppInsight3

 

The graph on top shows the distribution of crashes over the last 24 hours, and how many users were impacted by them, but we are eager to get to the culprit, and the table below is very clear:

 

AppInsight4

 

A specific System.ArgumentException is the major cause of concern here with 96,9% of crashes, so let's click on it to expand the crash information:

 

AppInsight5

 

The first half of the screen shows generic information about the environment hosting our app (OS version, device name) and the troubling version(s) of the app. Let's scroll down in this panel to get to the log of exceptions: 

 

AppInsight6

 

Here they are, logged and sorted by time of occurence! So let's click on the first one to see what happened:

 

AppInsight7

 

Now we know not only the exception thrown (System.ArgumentException) but also the method throwing the exception (GetThumbnailFileName). However, we're not done yet, as scrolling down reveals the Call Stack:

 

AppInsight8

 

Just remember to turn off "Show Just My Code", so that calls to the .NET CLR are visible too, and here we are: GetThumbnailFileName is calling System.IO.Path.GetDirectoryName, which in turn calls System.IO.Path.NormalizePath. With all these hints, debugging the code is very easy, the call to GetDirectoryName was using an invalid path name and causing the exception. Problem solved!

And there is more: as the code is logging Trace information, we can also see the full log surrounding the exception, understanding all the steps that lead to the crash such as user's actions:

 

AppInsight9

Quote this article on your site

To create link towards this article on your website,
copy and paste the text below in your page.




Preview :


Powered by QuoteThis © 2008
Last Updated on Saturday, 12 March 2016 15:01  
View Stefano Tommesani's profile on LinkedIn

Latest Articles

Fixing Git pull errors in SourceTree 10 April 2017, 01.44 Software
Fixing Git pull errors in SourceTree
If you encounter the following error when pulling a repository in SourceTree: VirtualAlloc pointer is null, Win32 error 487 it is due to to the Cygwin system failing to allocate a 5 MB large chunk of memory for its heap at
Castle on the hill of crappy audio quality 19 March 2017, 01.53 Audio
Castle on the hill of crappy audio quality
As the yearly dynamic range day is close (March 31st), let's have a look at one of the biggest audio massacres of the year, Ed Sheeran's "Castle on the hill". First time I heard the song, I thought my headphones just got
Necessary evil: testing private methods 29 January 2017, 21.41 Testing
Necessary evil: testing private methods
Some might say that testing private methods should be avoided because it means not testing the contract, that is the interface implemented by the class, but the internal implementation of the class itself. Still, not all
I am right and you are wrong 28 December 2016, 14.23 Web
I am right and you are wrong
Have you ever convinced anyone that disagreed with you about a deeply held belief? Better yet, have you changed your mind lately on an important topic after discussing with someone else that did not share your point of
How Commercial Insight changes R&D 06 November 2016, 01.21 Web
How Commercial Insight changes R&D
The CEB's Commercial Insight is based on three pillars: Be credible/relevant – Demonstrate an understanding of the customer’s world, substantiating claims with real-world evidence. Be frame-breaking – Disrupt the

Translate