使用NodeJS SDK引发错误时,如何在Application Insights中设置异常类型?

问题描述 投票:1回答:2

我的应用程序有很多自定义错误类型,它们是Error的子类。 Application Insights在门户网站中记录异常类型,但到目前为止,我只能让它显示该类型的通用“错误”。

enter image description here

看看来源似乎设置错误的name属性应该设置这个,但它没有任何区别。

enter image description here

我尝试发送以下内容,但它不会记录为MyError,

class MyError extends Error {
  constructor (msg) {
    super(msg)
    this.name = 'MyError'
  }
}

const error = new MyError('some message')

client.trackException({ exception: error, properties: { correlationId } })

我使用的是Azure NodeJS SDK的1.2.0版

有任何想法吗?

node.js azure-application-insights
2个回答
2
投票

它应该让你改变异常类型,你怎么做似乎是正确的。我稍微修改了你的例子,如下所示。

const appInsights = require('applicationinsights');
appInsights.setup('ikey')
  .setInternalLogging(true, true)
  .start();
appInsights.defaultClient.config.maxBatchSize = 1;

class MyError extends Error {
  constructor (msg) {
    super(msg)
    this.name = 'MyError'
  }
}

const error = new MyError('some message')

appInsights.defaultClient.trackException({ exception: error });

0
投票

根据执行上下文,错误的处理方式不同。没有真正的标准。以前我在mozilla页面找到了有用的帮助:Error management

抱歉,由于我选择不再使用人员类型的错误,因此我没有任何带有良好书面示例的回购。

© www.soinside.com 2019 - 2024. All rights reserved.