Azure Application Insights in Sitecore Applications

09 oktober 2020 om 10:00 by ParTech Media - Post a comment

In the modern world, user experience plays a significant role in driving sales by increasing the count of repeat users to a website. If you are a user, you will often consider your website experience as top-notch if the website runs at optimal performance. In other words, the optimal performance of the website plays a key role in determining the user experience of a website. Now the important question - how to measure the performance of a website and how can we improve it.

Think of a personal trainer in a gym. Here is a person who monitors our performance and advises us with the required exercise and diet plans. Similarly, we need a personal trainer for our website. Someone who can monitor our application, provide performance anomalies, and provide some analytics based on that.

Azure has an answer for this - Azure Application Insights. It is widely used to measure the performance of an application. Let us get into details starting from what is Azure Application Insights to how to use Azure Application Insights in Sitecore applications.

Table of Contents

  1. What is Azure Application Insights?
  2. Pain areas in using Sitecore Logs
  3. Application Insights with Sitecore
  4. Application Insights over logs
  5. Wrapping up

What is Azure Application Insights?

Application Insights is a Platform as a Service (PaaS) offering from Microsoft Azure. It is a lightweight application performance management service for web applications. It is used to monitor the live application, automatically detect performance anomalies, and even provides analytic tools to diagnose issues and understand the pattern of usage for the web application.

It supports a wide variety of platforms including Java, .NET, Node.js, and Python. With all these in-built features, Application Insights will be able to address timely issues and provide an opportunity to improve continuously.

Pain Points encountered while using Sitecore Logs

The advantage of using Sitecore over a tailor-made application is the number of built-in features that Sitecore provides, one of them being logging.

By default, Sitecore comes up with Log4Net based logging. It does not just provide the ability to write data to a log file, but also comes with built-in logic to delete the old log files which would stop your server's hard disk from filling.

However, on a large website solution, the standard logs often tend to get mammoth, and whenever we notice an installation issue, finding the exact trace information becomes a cumbersome task. We will revisit this in the later part of our article.

Application Insights with Sitecore

So far you have seen the most common pain point which is figuring out the errors from the logs when needed. So, it automatically leads to a question - “How to overcome this and how can we offer updates on the error or warn that it is happening on the website”.

Application Insights comes in handy here. From an issue perspective, we expect Sitecore to send errors, warnings, and info logs to Application Insights. Along with the Applications Insights, it captures Server response times, Page load time, Failed requests, Received Requests, and Application map with all connected components.

That is a lot of information we get from Application Insights. But, how is it going to help the technical support team who is still trying to find the error in the log, figure out the issue and fix the same?

Application Insights over logs

To see the advantages of using application insights over logs, consider a scenario where one of the pages on the website is throwing 500 errors and the technical support is trying to figure out the error.

If using logs, the technical support team has to get the information on the page which is erroring out and the date when it was erroring out. Then, the team has to go to the log directory and find the logs which are dated as mentioned by the user (if the user is from the same timezone as the server, then we can directly check the logs with the provided time else the team has to convert it to the timezone of the server and check the relevant logs).

Once the log file of the required data has been figured out, then the team has to open it using any text editors or specific tools for viewing logs and search for the keyword of the file to figure out the error. In case the search result does not provide any result, then the same has to be repeated for a few more log files of different timestamps (not all users who report the issue provide the exact date and time it happened).

Sometimes when we implement a load balancer and have multiple instances of the Sitecore application, the timestamp which the user provides will not be sufficient enough to figure out the issue at a single stroke. This is because the team has to first figure out which instance of the application was consumed by the user and search the required text on the particular dated log.

Once the search key is identified, the error description or stack traces have to be figured out from the logs to identify the root cause of the error. Doesn't it seem to be a tedious and laborious process? Definitely yes. Let's see how we can achieve the same using Application Insights.

In the case of Application Insights, to pull out information from all the instances of Sitecore, a ‘role’ filter can be applied to get the events from all the delivery instances of Sitecore. The next step is to filter out the exceptions. Now we can apply the date-time filter with a buffer time added to avoid user errors. All you have to do is follow the above steps and application insights will provide the list of errors that happened in all the instances during the provided time.

Image Source: Microsoft

Doesn’t it look simple? And isn't it a faster approach when compared to the conventional way of looking at logs?

Wrapping Up

Now that you have seen how to use Azure Application Insights in Sitecore applications, you would have realized that Azure Application Insights is a real gem when it is combined with Sitecore. Interestingly it is not confined only to Sitecore, it can be tied up with almost any web application that is running currently. It can also provide some cool analytical insights about the application in no time.