Application Insights - 2.4.0-beta3 的未定义云角色名称
Application Insights - Undefined Cloud Role Name with 2.4.0-beta3
我们正在试用此处宣布的应用洞察多角色预览:
https://azure.microsoft.com/en-us/blog/app-insights-microservices/
我们为 appinsights 添加了 2.4.0-beta3 包,appinsights.windowsserver 因为我们使用的应用目前托管在 prem (IIS) 上。
我们的 cloud_rolename
似乎在我们的请求遥测中未定义。除了更新软件包,我们还需要做些什么吗?
我们还发现了这个:
AzureRoleEnvironmentTelemetryInitializer
使用从 Azure 运行时环境中提取的信息更新设备上下文的 RoleName
和 RoleInstance
属性。
..虽然我们的 Cloud_RoleInstance
属性 正在正确填充。
确保添加所有相关的 appinsights 包。我的无状态服务结构服务遇到了同样的问题。添加 Microsoft.ApplicationInsights.ServiceFabric
包后 rolename
被添加到遥测数据中。
对于ASP.NET apps, I had to assign Cloud.RoleName
using a custom ITelemetryInitializer
to assign ITelemetry.Context.Cloud.RoleName
property which will assign the proper context for a given request when 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。
如果你想在应用洞察 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";
});
});
在网络应用程序中,Cloud_RoleName 是自动设置的环境变量 WEBSITE_SITE_NAME 的值当托管在 Azure 中时。
对于本地,您可以手动设置此变量。
对于调试环境变量,可以在 项目设置 > 调试 > 环境变量 (example).
中设置
Source code 的应用程序见解,其中检索到 Cloud_RoleName。
这是对 的编辑,但被拒绝了,这是不合逻辑的。
如果你想在应用洞察 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 初始化脚本将其添加到 layout/master 页面中,使其变为:
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
如果您使用的是 @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';
});
我们正在试用此处宣布的应用洞察多角色预览:
https://azure.microsoft.com/en-us/blog/app-insights-microservices/
我们为 appinsights 添加了 2.4.0-beta3 包,appinsights.windowsserver 因为我们使用的应用目前托管在 prem (IIS) 上。
我们的 cloud_rolename
似乎在我们的请求遥测中未定义。除了更新软件包,我们还需要做些什么吗?
我们还发现了这个:
AzureRoleEnvironmentTelemetryInitializer
使用从 Azure 运行时环境中提取的信息更新设备上下文的 RoleName
和 RoleInstance
属性。
..虽然我们的 Cloud_RoleInstance
属性 正在正确填充。
确保添加所有相关的 appinsights 包。我的无状态服务结构服务遇到了同样的问题。添加 Microsoft.ApplicationInsights.ServiceFabric
包后 rolename
被添加到遥测数据中。
对于ASP.NET apps, I had to assign Cloud.RoleName
using a custom ITelemetryInitializer
to assign ITelemetry.Context.Cloud.RoleName
property which will assign the proper context for a given request when 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。
如果你想在应用洞察 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";
});
});
在网络应用程序中,Cloud_RoleName 是自动设置的环境变量 WEBSITE_SITE_NAME 的值当托管在 Azure 中时。
对于本地,您可以手动设置此变量。
对于调试环境变量,可以在 项目设置 > 调试 > 环境变量 (example).
Source code 的应用程序见解,其中检索到 Cloud_RoleName。
这是对
如果你想在应用洞察 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 初始化脚本将其添加到 layout/master 页面中,使其变为:
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
如果您使用的是 @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';
});