如何使用哨兵v5全局忽略错误以减少噪声

时间:2019-04-25 10:03:49

标签: javascript vue.js sentry

使用已弃用的客户端Raven,您可以忽略麻烦的错误:

Raven.config('your-dsn', {
    ignoreErrors: [
        'Can\'t execute code from freed script',
        /SecurityError\: DOM Exception 18$/
    ]
}).install();

我发现新客户端的唯一方法是使用before-send钩子: https://docs.sentry.io/error-reporting/configuration/filtering/?platform=browser#before-send

import * as Sentry from '@sentry/browser';

init({
  beforeSend(event, hint) {
    const { message } = hint.originalException;
    if (message && message.match(/database unavailable/i)) {
      return null;
    }
    return event;
  }
});

我搜索了所有文档,但没有找到忽略错误的全局方法。

2 个答案:

答案 0 :(得分:2)

似乎有一个ignoreErrors配置选项。记录在他们的示例应用程序中:

https://github.com/getsentry/sentry-javascript/blob/ab7ba810a97a2acae3dbd2c82b07e3972147bb97/packages/browser/examples/app.js#L38

答案 1 :(得分:0)

普通JS:


process.on('unhandledRejection', (reason, promise) => {
  //console.log('(Custom message) Unhandled Rejection found at:', reason.stack, reason.caputureStackTrace);
  console.log('Unhandled Rejection at: Promise', promise, 'reason:', reason, reason.constructor.name);
});

我猜您的正则表达式不匹配,请尝试:/SecurityError\\: DOM Exception 18$/代替/SecurityError\: DOM Exception 18$/,注意\\