Search code examples
c#azureazure-application-insights.net-4.8

Where to add application name for Application Insights


Visual Studio 2022 with all updates and running on .Net Framework (not Core)

I would like to use Application Insights so when my app raises any relevant errors/events it is recorded to AppInsights.

I started with this tutorial https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net and created two different application along with having events being recorded which i can see in Azure App Insights.

When i view the data it has the same AppID for two applications i created. I cant find any document to suggest where i could change the appId or any other way to state the source of the event if from application one or application two.

After viewing the reports and documentation im not sure if i need to configure Azure App Insights differently or if i could change it at app level? I just want to be able to record any errors but also have a way to determine which application the error was raised from?

Edit

I have added the below class

public class ReportInitialise : ITelemetryInitializer
{
    public void Initialise(ITelemetry telemetry)
    {
        telemetry.Context.Cloud.RoleName = "Test";
        telemetry.Context.Cloud.RoleInstance = "TestInstance";
    }
}

Edit 2

In the MvcApplication class i added the below to Application_Start

TelemetryConfiguration.Active.TelemetryInitializers.Add(new ReportInitialise );

which resolved the last part of the puzzle


Solution

  • When i view the data it has the same AppID for two applications i created.

    That is correct. It is the ID of the Application Insights resource.

    After viewing the reports and documentation im not sure if i need to configure Azure App Insights differently or if i could change it at app level? I just want to be able to record any errors but also have a way to determine which application the error was raised from?

    Typically this is done by inspecting the cloud_RoleName property. In Web Apps afaik this is set to the web app name. You can override it using a telemetry initializer if you want.