Application Insights provides a powerful and easy to use solution for application monitoring. Both for server-side components and client-side components as well. Application Insights captures a plethora of information about clients by default but you can also add custom fields (also referred to as custom dimensions).
When the information gets logged it gets associated with an event name and a timestamp but all the custom fields are grouped into a JSON document stored in a single field called ‘customDimensions’.
You can see in the above example we have a couple fields visible in the JSON document “Environment” and “ErrorMessage”. “Hostname” is another such custom field however due to the limitation of this presentation we aren’t able to see it.
Very often its useful to return these custom fields in our Application Insights Reports. By simple adding the follow ‘extend’ command we are able to expose one of our custom dimensions as its own column.
As you can see, now the column ‘hostname’ has been added to the end of our columns.
In our scenario, we have clients connect to the service to report error conditions that occur client-side. When they do this they of course include their hostname. In order to identify which machines need attention we want to report on the number of errors that take place for each machine and group them so that each hostname only appears once with the # of errors incurred.
The above ‘project’ command essentially says that we only care about two fields: Timestamp and hostname. The ‘summarize’ command allows us to group the rows by the hostname field so we get the count of the events for that hostname next to the hostname itself. This is similar to a GROUP BY clause in T-SQL.
As you can see, the summarize command is aggregating the count of every occurrence of the particular hostname value in the custom field.
I’m very impressed with how far Application Insights has come. I love the Analytics features and how quick and easy it is to build useful reports based on incoming event streams.