如何在Angular中使用AppInsights?

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

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
}, { });

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

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

我尝试查看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:

  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,如下所示:

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.

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:

确定