asp.net-coreappinsights

App Insights ITelemetryInitializer / ITelemetryProcessor Not Working When Application Deployed to App Service


I'm attempting to include our application user ID in the app insights events that we send. This is a .Net Core web application. I've tried using both ITelemetryInitializer and ITelemetryProcessor.

The user ID is passed to app insights correctly when I'm running the application locally. However, once I deploy the application at Azure's App Service, the user ID no longer shows when viewing the app insights events through Azure portal.

Any thoughts on what could the telemetry initializer / processor to not run in an app service?

Thanks in advance!

Attempts I've tried are:

public class AddUserId : ITelemetryInitializer
    {
        public void Initialize(ITelemetry telemetry)
        {
            if (telemetry?.Context?.User != null && string.IsNullOrWhiteSpace(telemetry.Context.User.AuthenticatedUserId))
            {
                telemetry.Context.User.AuthenticatedUserId = "Test";
            }
        }
    }

// Startup.ConfigureServices:
services.AddSingleton<ITelemetryInitializer, AddUserId>();

and

public class AddUserId : ITelemetryProcessor
    {
        private ITelemetryProcessor Next { get; set; }
        public AddUserId(ITelemetryProcessor next)
        {
            this.Next = next;
        }
        public void Process(ITelemetry item)
        {
            item.Context.User.AuthenticatedUserId = "Test";
            this.Next.Process(item);
        }
    }

 // Startup.ConfigureServices:
 services.AddApplicationInsightsTelemetryProcessor<AddUserId>();

Solution

  • The problem was App Insights was added to the App Service through the Azure Portal in addition to being registered in code.

    Once I disabled App Insights on the App Service using the "Application Insights" blade, the telemetry initializer started to work.