One way to improve our Application Insights telemetry, is by setting the cloud role name yourself. I shared how to do this in an ASP.NET application in a previous post. In this post I'll show you how to use this approach in an ASP.NET Core application.
The first steps are quite similar. We still need to create a custom TelemetryInitializer. Therefore we create a class that implements the ITelemetryInitializer
interface and implement the Initialize
method:
Now, in the Startup.ConfigureServices
method, we register that telemetry initializer as a singleton:
Or if you are using .NET 6 minimal API’s: