英文:
How can I use AppInsights with Angular?
问题
我正在尝试在Angular中使用AppInsights:
import { AppInsights } from 'applicationinsights-js';
....
if (!AppInsights.config) {
var config: Microsoft.ApplicationInsights.IConfig = {
instrumentationKey: environment.appInsightsInstrumentationKey
};
AppInsights.downloadAndSetup(config);
}
// code for logging exception:
AppInsights.trackException(errorMessage, "GlobalErrorHandler", {
UserName: userName,
ViewName: url
}, { }, AI.SeverityLevel.Error);
// code for logging page views
AppInsights.trackPageView(name, url, {
UserName: userName,
ViewName: url
}, { });
我在这段代码中遇到了两个问题:
- 使用这段代码无法在应用程序洞察中跟踪异常。
- 虽然可以跟踪页面视图,但它不包含自定义属性。
我尝试查看AppInsights模块(applicationinsights-js)的源代码,但未找到解决方法。
感谢任何建议。
英文:
I am trying to use AppInsights with Angular:
import { AppInsights } from 'applicationinsights-js';
....
if (!AppInsights.config) {
var config: Microsoft.ApplicationInsights.IConfig = {
instrumentationKey: environment.appInsightsInstrumentationKey
};
AppInsights.downloadAndSetup(config);
}
// code for logging exception:
AppInsights.trackException(errorMessage, "GlobalErrorHandler", {
UserName: userName,
ViewName: url
}, { }, AI.SeverityLevel.Error);
// code for logging page views
AppInsights.trackPageView(name, url, {
UserName: userName,
ViewName: url
}, { });
I ran into two issues with this code:
- an exception is not tracked at all in app insights using this code, and
- a page view is tracked, but it does not contain the custom properties.
I tried to look into the source code of the module for AppInsights (applicationinsights-js), but could not find a solution.
Thank you for any advice.
答案1
得分: 2
an exception is not tracked at all in app insights using this code
请检查是否将disableExceptionTracking设置为true或false。
a page view is tracked, but it does not contain the custom properties
您应该尝试添加properties,如下所示:
AppInsights.trackPageView(name, url, properties:{
UserName: userName,
ViewName: url
}, { });
并且请尝试使用@microsoft/applicationinsights-web包。
英文:
> an exception is not tracked at all in app insights using this code
Please check if disableExceptionTracking is set to true or false.
> a page view is tracked, but it does not contain the custom properties
you should try to add properties like below:
AppInsights.trackPageView(name, url, properties:{
UserName: userName,
ViewName: url
}, { });
And also please try to use @microsoft/applicationinsights-web packages.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论