Search code examples
azureazure-service-fabricazure-application-insights

How to set Cloud_RoleName in Service Fabric


I'm trying to get a more user-friendly component name in Application Insights Application Map. I found examples but not for Service Fabric specifically.

How do you integrate that with the FabricTelemetryInitializer that is part of the Kestrel WebHostBuilder?


Solution

  • If you are not using the Application Insights Service Fabric nuget package, then you should use it to set your cloud role. https://www.nuget.org/packages/Microsoft.ApplicationInsights.ServiceFabric https://www.nuget.org/packages/Microsoft.ApplicationInsights.ServiceFabric.Native

    Microsoft.ApplicationInsights.ServiceFabric.Native should be used if your application has references to service fabric runtime since this library is relevant to concepts like ServiceContext, Service Remoting, etc. Microsoft.ApplicationInsights.ServiceFabric should be used if your application runs in service fabric but has no reference to service fabric runtime.

    Since you mentioned FabricTelemetryInitializer, I assume you are using these nuget packages already. You can see how FabricyTelemetryInitializer can be hooked up here: https://github.com/microsoft/applicationinsights-servicefabric#net-core-1

    If you don't have a service context object, then don't pass in one to the constructor and FabricTelemetryInitializer will just rely on environment variables.

    See here for the actual logic: https://github.com/Microsoft/ApplicationInsights-ServiceFabric/blob/master/src/ApplicationInsights.ServiceFabric/Shared/FabricTelemetryInitializer.cs#L81