如何在Angular中使用AppInsights?

huangapple go评论111阅读模式
英文:

How can I use AppInsights with Angular?

问题

我正在尝试在Angular中使用AppInsights:

  1. import { AppInsights } from 'applicationinsights-js';
  2. ....
  3. if (!AppInsights.config) {
  4. var config: Microsoft.ApplicationInsights.IConfig = {
  5. instrumentationKey: environment.appInsightsInstrumentationKey
  6. };
  7. AppInsights.downloadAndSetup(config);
  8. }
  9. // code for logging exception:
  10. AppInsights.trackException(errorMessage, "GlobalErrorHandler", {
  11. UserName: userName,
  12. ViewName: url
  13. }, { }, AI.SeverityLevel.Error);
  14. // code for logging page views
  15. AppInsights.trackPageView(name, url, {
  16. UserName: userName,
  17. ViewName: url
  18. }, { });

我在这段代码中遇到了两个问题:

  1. 使用这段代码无法在应用程序洞察中跟踪异常。
  2. 虽然可以跟踪页面视图,但它不包含自定义属性。

我尝试查看AppInsights模块(applicationinsights-js)的源代码,但未找到解决方法。

感谢任何建议。

英文:

I am trying to use AppInsights with Angular:

  1. import { AppInsights } from 'applicationinsights-js';
  2. ....
  3. if (!AppInsights.config) {
  4. var config: Microsoft.ApplicationInsights.IConfig = {
  5. instrumentationKey: environment.appInsightsInstrumentationKey
  6. };
  7. AppInsights.downloadAndSetup(config);
  8. }
  9. // code for logging exception:
  10. AppInsights.trackException(errorMessage, "GlobalErrorHandler", {
  11. UserName: userName,
  12. ViewName: url
  13. }, { }, AI.SeverityLevel.Error);
  14. // code for logging page views
  15. AppInsights.trackPageView(name, url, {
  16. UserName: userName,
  17. ViewName: url
  18. }, { });

I ran into two issues with this code:

  1. an exception is not tracked at all in app insights using this code, and
  2. 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,如下所示:

  1. AppInsights.trackPageView(name, url, properties:{
  2. UserName: userName,
  3. ViewName: url
  4. }, { });

并且请尝试使用@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:

  1. AppInsights.trackPageView(name, url, properties:{
  2. UserName: userName,
  3. ViewName: url
  4. }, { });

And also please try to use @microsoft/applicationinsights-web packages.

huangapple
  • 本文由 发表于 2020年1月6日 20:04:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611787.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定