VS Application Insights for a web application deployed in multiple environments

I am trying to run MS Application Insgihts in a web application deployed on Azure.

One thing that doesn't seem to be available out of the box is sharing statistics / anayltics using a deployment environment.

Just wondering, has anyone done this already and how did you manage to achieve it?

Here is what I thought.

  • Create 4 separate applications in AI (each with its own application name and component identifier)

  • Add one ApplicationInsights.config to your web application project

  • Manually add App.Config Convert to an application to replace ComponentName and ComponentId during build based on Configuratoin (QA, UAT or Prod)

  • Add conditional compilation symbols to the web application assembly configuration (QA, UAT, PROD)

  • Add the "#if QA" preprocessor directives to the _layout razor view to replace the correct ComponentId with a javascript fragment during build.

Thoughts?

+6
source share
2 answers

Here is what we did.

  • Create 4 AI Applications
  • In our ApplicationInsights.config, we install it in our developmentId component.
  • For Test, Stage, and Prod, we use a script construct that replaces the name componentId and componentName based on the environment in which we are located.
  • In javascript layout get appId:

    appInsights.start("@ServerAnalytics.ApplicationInsightsId"); 
+6
source

I found this on msdn blogs since January 7, 2015. Application support for multiple environments, stamps and application versions .

Basically, you can remove the toolkit key from ApplicationInsights.config and put it in Web.config as an application, and then install it at startup.

This means that you can save the configuration for each medium directly in azure.

My steps:

  • Remove <InstrumentationKey> from ApplicationInsights.config
  • Add a parameter to Web.config

    <add key="appInsightsInstrumentationKey" value="id_from hre"/>

  • Add settings to porta.azure.com for Dev, Sta, etc.
  • At startup:

    var aiInstrumentationKey = System.Web.Configuration.WebConfigurationManager.AppSettings["appInsightsInstrumentationKey"]; if( string.IsNullOrEmpty(aiInstrumentationKey)) { throw new ApplicationException("appInsightsInstrumentationKey missing in web.config"); } Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = aiInstrumentationKey;

0
source

All Articles