应用程序见解 - 未定义的云角色名称,带有2.4.0-beta3

时间:2017-05-23 14:14:14

标签: azure azure-application-insights

我们正在尝试按照此处公布的应用洞察多角色预览:

https://azure.microsoft.com/en-us/blog/app-insights-microservices/

https://docs.microsoft.com/en-us/azure/application-insights/app-insights-monitor-multi-role-apps#use-cloudrolename-to-separate-components

我们为appinsights&添加了2.4.0-beta3软件包。 appinsights.windowsserver作为我们正在使用的应用程序当前托管(IIS)。

我们的settings.py似乎在我们的遥测请求中未定义。除了更新软件包之外,还有什么需要做的吗?

我们也发现了这个:

cloud_rolename使用从Azure运行时环境中提取的信息更新所有遥测项目的设备上下文的AzureRoleEnvironmentTelemetryInitializerRoleName属性。

..虽然我们的RoleInstance属性已正确填充。

6 个答案:

答案 0 :(得分:4)

对于ASP.NET apps,我必须使用a custom ITelemetryInitializer分配Cloud.RoleName来分配ITelemetry.Context.Cloud.RoleName属性,该属性将在using multi-component apps时为给定请求分配正确的上下文。

多组件应用程序的遥测初始化程序

  public class MultiComponentTelemetryInitializer : ITelemetryInitializer
  {
    public void Initialize(ITelemetry telemetry)
    {
        var requestTelemetry = telemetry as RequestTelemetry;
        if (requestTelemetry?.Context?.Cloud == null) return;
        requestTelemetry.Context.Cloud.RoleName = "myapp-api";
    }
  }

此初始化程序仅适用于服务器端API - 我有not found the equivalent hook for the client JS SDK

答案 1 :(得分:3)

在网络应用程序中, Cloud_RoleName 是环境变量 WEBSITE_SITE_NAME 的值,该值在Azure中托管时自动设置。
对于内部部署,您可以手动设置此变量 对于调试环境变量,可以在项目设置>中设置。调试>环境变量 (example)

Source code应用洞察,其中 Cloud_RoleName 被检索。

答案 2 :(得分:2)

如果您希望将云角色实例和名称包含在应用洞察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";
});

});

答案 3 :(得分:1)

确保添加所有相关的appinsights包。我的无状态服务结构服务遇到了同样的问题。添加Microsoft.ApplicationInsights.ServiceFabric包后rolename会添加到遥测数据中。

答案 4 :(得分:1)

这是对Brian's answer的修改,但被拒绝了,这是不合逻辑的。

如果您想在应用程序见解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.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:Modifying and Filtering Telemetry with AppInsights JavaScript SDK Telemetry Initializer

资料来源2:Filtering and preprocessing telemetry in the Application Insights SDK

SDK参考:addTelemetryInitializer

答案 5 :(得分:0)

如果您使用@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';
});
相关问题