Is there a way to set appName in Application Insights custom events?

There is a preview where you can set the application name. This is done in the following way:

  • enable the preview Application Map
  • set the ITelemetry.Context.Cloud.RoleName (this is the application name)

Enable preview: Go to the portal -> the application insights -> previews -> Enable Multi-role Application Map

Set the application name:

This is done by adding an interceptor:

public class ServiceNameInitializer : ITelemetryInitializer
{
    public void Initialize(ITelemetry telemetry)
    {
        telemetry.Context.Cloud.RoleName = "MyProcessName";
        // RoleInstance property modifies the app name in the telmetry dashboard
        telemetry.Context.Cloud.RoleInstance = "MyAppInstanceName";
    }
}

Add the interceptor to the application insights configuration in startup.cs:

private void ConfigureAppInsights(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry(Configuration);
    TelemetryConfiguration.Active.TelemetryInitializers
       .Add(new ServiceNameInitializer());
}

Read more at: cross-process-application-insights-with-multi-role-application-map


Those values are populated in the backend and specify Application Insights resource details and thus cannot be changed.

What your're looking for is custom dimensions.

For example, to send the telemetry:

EventTelemetry telemetry = new EventTelemetry("my custom event");
telemetry.Properties.Add("MyApp", "HelloWorld");
telemetryClient.TrackEvent(telemetry);

To query those custom dimensions:

customEvents
| where customDimensions['MyApp'] == "HelloWorld"