【问题标题】:How to globally ignore errors with sentry v5 to reduce noise如何使用 sentry v5 全局忽略错误以减少噪音
【发布时间】:2019-09-14 17:35:27
【问题描述】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,这正是我想要的!
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      简单,我在 nuxt.config.js 中将此配置用于 nuxtjs 应用程序

        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
            }
          }
        },
      

      【讨论】:

        猜你喜欢
        • 2018-10-03
        • 1970-01-01
        • 2016-10-02
        • 1970-01-01
        • 1970-01-01
        • 2012-08-15
        • 1970-01-01
        • 2011-06-10
        • 1970-01-01
        相关资源
        最近更新 更多