Application Insights in multiple environments

The destination of the telemetry is determined by the so-called instrumentation key (iKey), which is sent along with every telemetry message. Problem: diagnostics data from DEV and PROD can interfere. Why? When you deploy a web app from Visual Studio, the ApplicationInsights.config is included. The ApplicationInsights config file holds the instrumentation key and is the same for DEV and PROD, because you have one code base.

Where do you find the instrumentatio key. Go to the Azure Portal. Select Application Insights and go to Properties.

Next, also in the Azure Portal. Go to the web app and scroll down to the Application Insights menu option. On the Application Insights pane you can see, you can change the Application Insights resource for the web app. Addition: changing the Application Insights resource this way, may not work. An alternative approach is to start up Kudu (ie. en change the instrumentation key in the ApplicationInsights.config file. You can also do this automatically via global.asax / app_start or by changing the web.config. Additional reading: MSDN Blog

Note: Changing the Application Insights resource of a web app should be done post deployment. When you redeploy the web app, this setting will be lost and must be reset as well.