Insights on Application Insights

James Grergory James Gregory | August 07, 2017 Comments
Insights on Application Insights

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:

  1. Get the goods (dlls and configs)
    1. Log in to dev.sitecore.net
    2. Navigate to the download page for your version of sitecore
    3. Download a package from the "Download options for Azure AppService" section. Choose XPO (single instance), it is the smallest.
      1. 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.
    4. Unzip the downloaded file
      1. Drill down to the scwdp.zip file and unzip that too
        1. Drill down to the /Content/Website folder
  2. Copy what we need
    1. The source will be the ../Content/Website folder from the downloaded deployment package
    2. The target will be the Website folder of whichever Sitecore instance you are working with
    3. 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.
    4. Identify and copy these files:
      1. /ApplicationInsights.config
      2. /App_Config/Include/zzz/Sitecore.Cloud.ApplicationInsights.config
      3. /bin/
        • Microsoft.AI.*
          Microsoft.ApplicationInsights.*
        • Sitecore.Cloud.ApplicationInsights.*
    5. Add this connection string to /App_Config/ConnectionStrings.config
      1. <add name="appinsights.instrumentationkey" connectionString="place-your-guid-key-here"/>
        1. The value of the connectionString is the Instrumentation Key, found under properties:
          GUID-screen
    6. 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.
      1. Here are the transforms for the relevant areas:
    
        <!-- Application Insights -->
        <system.webServer>
            <modules>
                <remove xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" name="ApplicationInsightsWebTracking"/>
                <add xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"
                     name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/>
            </modules>
        </system.webServer>
        <system.web>
            <httpModules xdt:Transform="InsertIfMissing">
                <add xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"
                     name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
            </httpModules>
        </system.web>
     
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly xdt:Transform="Insert">
                    <assemblyIdentity name="Microsoft.AI.Agent.Intercept" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
                    <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0"/>
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
     
        <system.diagnostics xdt:Transform="InsertIfMissing">
            <trace xdt:Transform="InsertIfMissing" autoflush="true" indentsize="0">
                <listeners xdt:Transform="InsertIfMissing">
                    <add xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"
                         name="myAppInsightsListener"
                         type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener"/>
                </listeners>
            </trace>
        </system.diagnostics>

    That's it! The only unique part is the connection string value.

    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 Insight.

    There are many other benefits too like smart monitoring and reporting features.

Contact_US_CTA

Write a review

Authors

  • James Grergory
  • Ellis LaMay Blog Author Image
  • Mani Blogger Image
  • Elin-Alexander
  • David-Dillon
  • Ahmed Okour
  • Paul-Ross-Blogger-Bio-Pic
  • Rachel-B-Web
  • Courtney-V4
  • scottstiles
  • stu-3
  • Joseph Gustafson
  • Vince Scarlata
  • Tim Ahlenius
  • Staff Blogs
  • shawn griffin blogger image
  • Americaneagle Partner
  • Nick Goodrum
  • Missy Hildebrand
  • corte-swearingen-director-ab-testing
  • Emily Stark