我使用的是AppInsights的NPM版本,似乎无法将这个遥测初始化器附加到每个传出信封上:
import { ApplicationInsights } from '@microsoft/applicationinsights-web'
appInsights = new ApplicationInsights({ config: {
instrumentationKey: 'removed',
autoTrackPageVisitTime: true
}});
appInsights.loadAppInsights();
var userInitializer = (envelope) => {
var telemetryItem = envelope.baseData;
telemetryItem.properties = telemetryItem.properties || {};
telemetryItem.properties["role"] = userProfile.role;
}
appInsights.queue.push(function () {
appInsights.context.addTelemetryInitializer(userInitializer);
});问题是appInsights.queue总是未定义的。我唯一能找到的就是将它包装在一个检查中,以确保它不会尝试执行两次,但这里不是这种情况,它永远不会执行。如果我在每次跟踪之前单独调用遥测初始化器,它就可以正常工作,如下所示:
appInsights.addTelemetryInitializer(userInitializer);
appInsights.trackPageView();当I console.log(appInsights)时,肯定没有队列属性,但在每个示例中都是这样使用的。
发布于 2020-05-14 20:07:02
这对我们很有效
this.appInsights.addTelemetryInitializer(envelope => {
envelope.tags['ai.cloud.role'] = 'your cloud role name';
envelope.baseData.properties['item'] = 'some property';
});发布于 2019-06-10 17:39:56
当代码被调用两次时就会发生这种情况,第二次调用时就不再有"queue“了。解决方案是使用带检查的代码片段
if (this.AppInsights.queue) {
this.AppInsights.queue.push(function() {
this.AppInsights.context.addTelemetryInitializer(function(envelope) {
var telemetryItem = envelope.data.baseData;
telemetryItem.Properties = telemetryItem.Properties || {};
telemetryItem.Properties["prop1"] = "This is a custom property";
telemetryItem.Properties["prop2"] = "This is another custom property";
});
});
}希望能有所帮助。
发布于 2019-06-18 23:58:22
你应该能够做到
appInsights.addTelemetryInitializer(userInitializer);https://stackoverflow.com/questions/56506942
复制相似问题