This was an edit to Brian's answer but it was rejected which is illogical tbh.
If you want to include cloud role instance and name with the app insights js sdk, I had success doing this:
appInsights.queue.push(() => {
appInsights.context.addTelemetryInitializer((envelope) => {
envelope.tags["ai.cloud.role"] = "your role name";
envelope.tags["ai.cloud.roleInstance"] = "your role isntance";
});
});
You should add this in your layout/master pages with the Application Insights initialization script right before appInsights.trackPageView(); so it becomes:
var appInsights=window.appInsights||function(config)
{
function r(config){ t[config] = function(){ var i = arguments; t.queue.push(function(){ t[config].apply(t, i)})} }
var t = { config:config},u=document,e=window,o='script',s=u.createElement(o),i,f;for(s.src=config.url||'//az416426.vo.msecnd.net/scripts/a/ai.0.js',u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=['Event','Exception','Metric','PageView','Trace','Ajax'];i.length;)r('track'+i.pop());return r('setAuthenticatedUserContext'),r('clearAuthenticatedUserContext'),config.disableExceptionTracking||(i='onerror',r('_'+i),f=e[i],e[i]=function(config, r, u, e, o) { var s = f && f(config, r, u, e, o); return s !== !0 && t['_' + i](config, r, u, e, o),s}),t
}({
instrumentationKey:'Instrumentation Key'
});
window.appInsights = appInsights;
appInsights.queue.push(() => {
appInsights.context.addTelemetryInitializer((envelope) => {
envelope.tags["ai.cloud.role"] = "your role name";
envelope.tags["ai.cloud.roleInstance"] = "your role isntance";
});
});
appInsights.trackPageView();
Source1: Modifying and Filtering Telemetry with AppInsights JavaScript SDK Telemetry Initializer
Source2: Filtering and preprocessing telemetry in the Application Insights SDK
SDK Reference: addTelemetryInitializer