If you’re planning to use Azure Application Insights for Sitecore, you’ll quickly found that the Application Map report is showing quite an unusual repots.
The mismatched number of instances reported aside, the server name being reported isn’t what I expected.
From inspecting the processor in the initialize pipeline from Sitecore, I can see the following.
1 2 3 4 5 6 7 8 9 |
public class SitecoreRoleInstanceInitializer : ITelemetryInitializer { public void Initialize(ITelemetry telemetry) { telemetry.Context.Component.Version = Sitecore.SecurityModel.License.License.Version; telemetry.Context.Properties["Role"] = Settings.GetSetting("ApplicationInsights.Role", "Single"); telemetry.Context.Properties["InstanceName"] = Settings.InstanceName; } } |
This doesn’t quite match what the Microsoft documentation suggested. And I can confirm by going to the logs captured in App Insights that the cloud_RoleName value is not passed at all.
The fix is quite simple, just use the following code to register the right CloudRoleName
1 2 3 |
public void Initialize(ITelemetry telemetry) { telemetry.Context.Cloud.RoleName = Settings.GetSetting("ApplicationInsights.Role", "Single"); } |
Soon after I can see the right role displayed in the App Insights Application Map Dashboard.
Now I have better visibility on the application dependencies and which area of my application that can be further optimized for performance.
Note: If you’re using Sitecore Experience Commerce, you’ll need to make some changes with the same approach in order to set the value for CloudRoleName as well.