Azure Application Insights-2.4.0-beta3中未定义的云角色名称

Azure Application Insights-2.4.0-beta3中未定义的云角色名称,azure,azure-application-insights,Azure,Azure Application Insights,我们正在试用AppInsights多角色预览,如下所示: 我们已经为appinsights&appinsights.windowsserver添加了2.4.0-beta3软件包,因为我们正在使用的应用程序当前托管在prem(IIS)上 我们的cloud\u rolename在我们的遥测请求中似乎没有定义。除了更新软件包,我们还有什么需要做的吗 我们还发现: AzureRoleEnvironmentTelemetryInitializer使用从Azure运行时环境提取的信息,更新设备上下文的R

我们正在试用AppInsights多角色预览,如下所示:

我们已经为appinsights&appinsights.windowsserver添加了2.4.0-beta3软件包,因为我们正在使用的应用程序当前托管在prem(IIS)上

我们的
cloud\u rolename
在我们的遥测请求中似乎没有定义。除了更新软件包,我们还有什么需要做的吗

我们还发现:

AzureRoleEnvironmentTelemetryInitializer
使用从Azure运行时环境提取的信息,更新设备上下文的
RoleName
RoleInstance
属性


…尽管我们的
Cloud\u RoleInstance
属性已正确填充。

请确保添加所有相关的appinsights软件包。我的无状态服务结构服务也有同样的问题。在添加
Microsoft.ApplicationInsights.ServiceFabric
rolename
后,将其添加到遥测数据中。

对于,我必须使用分配
Cloud.rolename
来分配
ITelemetry.Context.Cloud.rolename
属性,该属性将在以下情况下为给定请求分配适当的上下文

用于多组件应用程序的遥测初始化器
公共类多组件遥测初始化器:ITelemetryInitializer
{
公共无效初始化(ITelemetry遥测)
{
var requestTelemetry=作为requestTelemetry的遥测;
if(request遥测?.Context?.Cloud==null)返回;
requestTelemetry.Context.Cloud.RoleName=“myapp api”;
}
}

此初始值设定项仅适用于服务器端API-我有。

如果您想在app insights js sdk中包含云角色实例和名称,我成功地做到了这一点:

appInsights.queue.push(() => {
appInsights.context.addTelemetryInitializer((envelope) => {
  envelope.tags["ai.cloud.role"] = "your role name";
  envelope.tags["ai.cloud.roleInstance"] = "your role isntance";
});
appInsights.queue.push(() => {
    appInsights.context.addTelemetryInitializer((envelope) => {
      envelope.tags["ai.cloud.role"] = "your role name";
      envelope.tags["ai.cloud.roleInstance"] = "your role isntance";
    });
});

}))

在web应用程序中,Cloud\u RoleName是一个环境变量的值WEBSITE\u SITE\u NAME,它在Azure中托管时自动设置。
对于内部部署,您可以手动设置此变量。
对于调试,可以在“项目设置”>“调试”>“环境变量”中设置环境变量


检索到Cloud\u RoleName的应用程序洞察。

这是对的编辑,但被拒绝,不合逻辑。


如果您想在app insights js sdk中包含云角色实例和名称,我成功地做到了这一点:

appInsights.queue.push(() => {
appInsights.context.addTelemetryInitializer((envelope) => {
  envelope.tags["ai.cloud.role"] = "your role name";
  envelope.tags["ai.cloud.roleInstance"] = "your role isntance";
});
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()之前使用Application Insights初始化脚本将其添加到布局/母版页中因此它变成:

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();    
资料来源1:

资料来源2:


SDK参考:

如果您使用的是
@microsoft/applicationinsights web
npm软件包,则较短的版本为:

const appInsights = new ApplicationInsights({
    config: {
        instrumentationKey: 'your instrumentation key'
    }
});
appInsights.loadAppInsights();
appInsights.addTelemetryInitializer((telemetryItem) => {
    telemetryItem.tags['ai.cloud.role'] = 'your app name';
});

有25个nuget包和关于这些东西的非常低的文档,可以在.NET web应用程序Global.asax.cs或ApplicationInsights.config中调用Initialize方法。建议使用哪种方法。对于.NET应用程序,我会在
Global.asax.cs
中锁定
Application\u Start()
,对于.NET核心应用程序,我会在
ConfigureServices()
中锁定
ConfigureServices()
,在处理请求之前,您需要配置初始值设定项