I have a multi-tier web application that has been moved to Azure, however I would like to know how I can configure application insights for multiple environments as I have 3 separate resource groups for DEV, QA, and PROD. In each would like to have an instance of application insights to record diagnostic information for each environment but how would I configure this in my application?
There are 2 parts to the answers for your question.
Part 1
As part of the configuring AI(Application Insights) in cloud, you just have to create a new instance in the respective resource groups and Azure will automatically configure it for you.
Now on the overview panel of the instance, get the Application Insights Key
or the Instrumentation key
. This key will act as an unique identifier to your instance to which you want to send telemetry to.
Part 2
Make use the Microsoft.ApplicationInsights package
in your project by installing it.
Have a look at the sample template code here: https://learn.microsoft.com/en-us/azure/azure-monitor/app/console
Note: It is better to keep the Intrumentation key
as part of the release variables of your CD pipeline, as it would be easy to manage all the 3 environments.