Search code examples
visual-studio-2015azure-application-insights

Significance of Application Insights csproj file modifications


When I use the "Add Application Insights Telemetry..." menu option available from right-clicking an ASP.NET application in the Solution Explorer in Visual Studio to point an application to an existing Application Insights resource, the resulting file changes include the addition of two items to the .csproj file:

<ApplicationInsightsResourceId>/subscriptions/$guid/resourcegroups/$rgname>/providers/microsoft.insights/components/$name</ApplicationInsightsResourceId>
<ApplicationInsightsAnnotationResourceId>/subscriptions/$guid/resourcegroups/$rgname/providers/microsoft.insights/components/$name</ApplicationInsightsAnnotationResourceId>

I have elided some information - $guid is the Azure subscription GUID and $rgname and $name are the names given to the Application Insights resource group and resource respectively.

  1. What is the difference between each element? They seem to have the same information.

  2. If I want to send telemetry to different Application Insights resources in difference environments, the documentation tells me I need to set the instrumentation key for each environment in code - which is fine - but what about these settings? Are they used for anything other than driving the context-sensitive menu options in Visual Studio? Do I need to worry about them in other environments?


Solution

  • These are purely used by Visual Studio tools. They are in the csproj so all users who get your project (out of source control) or whatever, all have the values. (if it was stored in the registry or .suo or other non-source places, it wouldn't "travel" with the project)

    ApplicationInsightsResourceId is the resource id of the project which is used to display information in the configuration window about what resource VS thinks you are sending data to. This is also used by default to show data in codelens/etc. You can override this in the configure window to pick a different resource (like if you have data sent to a debug/staging resource when developing, but always want codelens/other tools to show data from prod always) Changing the resource inside the configuration window will set this property (and will update the ikey in your applicationinsights.config file)

    ApplicationInsightsAnnotationResourceId is the resource that VS will try to submit publish release annotations to if you publish your web app from inside Visual Studio. you can change this resource (or turn off this behavior entirely) from inside the configuration window as well. If you don't publish from inside VS, this setting doesn't do anything.

    These settings do not affect where the data actually goes at runtime, If you are setting your instrumentation key in code your data will still go there.