I have an V4 Azure function running .net6 as a isolated process. I want to set the Cloud role name in Application insights so I created class that inherits ITelemetryInitializer.
public class MyOwnTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
telemetry.Context.Cloud.RoleName = "MyAppName";
}
}
Then I inject it in the main function
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(s =>
{
s.AddSingleton<ITelemetryInitializer, MyOwnTelemetryInitializer >();
})
.Build();
host.Run();
}
I also set the "APPINSIGHTS_INSTRUMENTATIONKEY" in the locl.settings.json
The logging to application insights is working, but the Initialize() in MyOwnTelemetryInitializer never get call. What am I missing?