3

I've been reading several blog posts about application insights and Sitecore logs, and I've not been able to get the proper configuration working. This is using Sitecore 9 ARM templates on Azure app service.

We've got a QA instance that has one AI instance, and a CM/CD instance set that has another AI instance. Doing some reading, I saw that I needed to edit the ApplicationInsights.config file in the web root to include the InstrumentationKey value from the AI properties. I did this for the appropriate environment instance, using the App Service Editor (since the keys are different per environment, I didn't want to include the config file in my project root).

I did a restart of my QA app service as a test, then logged into Sitecore and bounced around. I then went to the Azure portal and to the AI instance for my QA, and clicked the Search option to check for the last 24 hours. I didn't get any results, and I'd expect to at least get the "audit" message when I logged in as admin, if not all the startup messages I'm used to seeing in the Sitecore log files.

I'm not sure if there's a time point at which log results write over, if I'm looking in the wrong place, or if there's additional configuration required. I haven't seen a good definitive "this is how you do it" blog on the matter (though I intend to write one once I have this figured out).

1 Answer 1

11

How it works

Have a look at the App_Config/Sitecore/Azure/Sitecore.Cloud.ApplicationInsights.config which gets deployed to all CM/CD/PRC/REP roles.

You will see that all the built-in log4net appenders get patched to append via the Application Insights LevelTraceAppender.

You may also notice that sitecore still logs to the file system on Azure PaaS, which is done via the App_Config/Sitecore/ExperienceContentManagement.Administration/Sitecore.ExperienceContentManagement.Administration.config. This essentially works by patching in an extra file appender to all built-in log4net loggers.

Troubleshooting

If you are not seeing any logs - check your appinsights.instrumentationkey value that is set in ConnectionStrings.config is correct - it should match the Instrumentation Key displayed on your Application Insights resource. AI logs should appear in the AI search within 1 or 2 minutes.

Another thing to check is that you are not over the daily volume cap. This can be configured by going to the Application Insights resource in the portal -> Configure -> Usage and estimated costs -> Daily cap. You can then see a graph of current usage and change the usage cap. I have found that the default of 0.33GB is too low for a standard installation - usually 1GB is enough, but you may need 2GB or more on a production install.

Finally - go to /sitecore/admin/showconfig.aspx on your CM role and make sure all the above mentions configs are loading correctly. If they are not - you may need to check your appSettings search:define and role:define values.

Enable Live Metrics Stream trace

In 9.0.2 and below, the ApplicationInsights dll's are too old for this to work. For this reason I usually install Microsoft.ApplicationInsights.Web in a project on the solution so that the latest dll's are deployed along with the rest of the code.

Enable Application Map

On all roles, in the wwwroot/ApplicationInsights.config, uncomment the line containing the DependencyTrackingTelemetryModule. A caution though - it nearly doubles your ApplicationInsights data usage.

Querying Application Insights

Sitecore's method of querying the logs is not the easiest in my opinion - I prefer to search using the query builder.

  • Go to the Application Insights resource and click the Analytics button on the Overview tab.
  • The query builder will open. Paste in the following query:

traces
| project timestamp, message, severityLevel, customDimensions.Role, customDimensions.InstanceName
| order by timestamp desc

  • Select the time range and click Run
3
  • So with v9, you don't need to modify the ApplicationInsights.config file? I see the key in the connection string. I see the references in the showconfig.aspx to the config files you mentioned as well, but the only thing I see in the AI logs is about performance counters not available in the web app supported list. My understanding is if I search for the last 24 hours of logs, I should basically see all of the Sitecore logs as if I was opening the log files. Sounds like maybe I should ping Sitecore support? Commented Sep 13, 2018 at 14:03
  • @KenMcAndrew You don't need to modify the ApplicationInsights.config file. Also I've just updated the post with how I query. Have you checked the file system logs for any error about why the AI logging isn't working? Commented Sep 13, 2018 at 23:13
  • I haven't seen any logs on errors, but I spun up my own single instance of Sitecore on my own Azure subscription, and after connecting the app service to AI, I'm getting log results as expected. So either some config setting we put in a patch knocked it out, or something got misconfigured during the setup. Thanks for all the guidance! Commented Sep 15, 2018 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.