如何使用sentry v5全局忽略错误以减少噪音

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

使用已弃用的客户端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;
  }
});

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

javascript vue.js sentry
2个回答
2
投票

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

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


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$/,请注意\\

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