首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用sentry v5全局忽略错误以减少噪声

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

Stack Overflow用户
提问于 2019-04-25 18:03:49
回答 3查看 12.6K关注 0票数 2

使用不推荐使用的客户端Raven,您可以忽略麻烦的错误:

代码语言:javascript
复制
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

代码语言:javascript
复制
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;
  }
});

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-04-25 18:10:25

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

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

票数 14
EN

Stack Overflow用户

发布于 2021-11-12 09:42:08

很简单,我在nuxt.config.js中为nuxtjs应用程序使用了这个配置

代码语言:javascript
复制
  sentry: {
    disabled: process.env.APP_ENV === 'development',
    dsn: 'xxxx'
    maxBreadcrumbs: 50,
    config: {
      environment: process.env.APP_ENV,
      debug: process.env.APP_ENV === 'development',
      release: '1.0.0',

      beforeSend: (event, hint) => {
        // see all errors, what you wants. 
        // using console.log(hint.originalException)

        // for example, not send when error code 404 when using axios
        const { response } = hint.originalException
        if (response && response.status && response.status === 404) {
          return null
        }
        return event
      }
    }
  },
票数 1
EN

Stack Overflow用户

发布于 2019-04-25 18:13:33

普通JS:

代码语言:javascript
复制
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$/,注意\\

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55846690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档