Wondering how to use Application Insights with your Sitecore project? Here is a quick reference on how to add it.
Application Insights is an Application Performance Management service which notably has a user interface to filter and view logged messages and is rising in popularity with Sitecore implementations. Sitecore has made an implementation available for cloud deployments that sends Sitecore logging and performance counters to Application Insights. We can borrow it for any Sitecore instance even those not hosted in the cloud.
A number of articles share the benefits of leveraging the cloud based tool, but I haven't seen any showing how to configure it. So for those not as familiar with Sitecore's Azure deployment packages here is a quick guide for how to send Sitecore's logging to Application Insights.
Prerequisites… you will need:
- A Sitecore instance - works with any regardless of hosting (ie. doesn't need to be in the cloud)
- A Sitecore certified account - You'll need to download the needed files.
- An Azure subscription is required to provision the Application Insights app.
- You can sign up with a free developer subscription for testing. You are required to enter a credit card, but not to fear, Microsoft provides a spending limit of $0 so you will not be charged if you don't want to be. A developer account is refreshed with 25 credits monthly, no charge.
- A provisioned Applications Insights app
- Remember there is a daily space cap for the free Application Insights… so you'll need a paid account for a production instance… or really clean logs :)
Steps to get it going:
- Get the goods (dlls and configs)
- Log in to dev.sitecore.net
- Navigate to the download page for your version of sitecore
- Download a package from the "Download options for Azure AppService" section. Choose XPO (single instance), it is the smallest.
- These packages are typically used with Sitecore's Azure Toolkit to provision the resources and deploy a clean install of Sitecore as an Azure App, but we just be pulling a few of the files.
- Unzip the downloaded file
- Drill down to the scwdp.zip file and unzip that too
- Drill down to the /Content/Website folder
- Copy what we need
- The source will be the ../Content/Website folder from the downloaded deployment package
- The target will be the Website folder of whichever Sitecore instance you are working with
- NOTE: there are a couple paths you could go here. You could either install the Application Insights nuget package in you code solution in order to get the dependency dlls and Webconfig transformations, or you can just extract what you need from the sitecore package. I opted for the latter.
- Identify and copy these files:
- Add this connection string to /App_Config/ConnectionStrings.config
- <add name="appinsights.instrumentationkey" connectionString="place-your-guid-key-here"/>
- The value of the connectionString is the Instrumentation Key, found under properties.
- Add sections to the Web.config.
NOTE: I chose to copy these areas from the Sitecore package to match that version of Application Insights instead of using the Application Insights NuGet package.
It's worth noting there are some configs worth reviewing at the bottom of the config file "zzz/Sitecore.Cloud.ApplicationInsights.config". Performance counters are defaulted off, but can be enabled. You can also set the ApplicationInsights.Role setting with labels like "CD" or "CM" if you want to consolidate logs from several Sitecore instances into one account and filter by the instance.
Sitecore posted documentation showing how to navigate the logs in Application Insights.
There are many other benefits too like smart monitoring and reporting features.