Hi @SL
According to the SDK repo, you can set the instrumentation key programmatically as follows,
// You do not need this if you have instrumentation key in the ApplicationInsights.config
TelemetryConfiguration.Active.InstrumentationKey = "Your_Resource_Key";
System.Diagnostics.Trace.TraceWarning("Slow response - database01");
You can use an application setting in place of Your_Resource_Key
. Do note though that is recommended to use the connection string of the application insights resource. As far as I know, it's interchangeable, meaning you can set InstrumentationKey
to that value and the telemetry should still flow through. Depending on your scenario and workstream, just using the app insights connection string is all that you should need. Therefore, no need for vars containing the resource group, resource id, subscription, etc.
If it were me, I would use the above code snippet and leverage app service app settings to set the instrumentation connection string for each web app. The app setting can also be used locally, making management fairly simple. Furthermore, I don't think you need multiple app insight resources. What I would personally do is have a resource for each environment, i.e. production, testing, UAT; an appropriate separation.