【问题标题】:How to log 4xx errors into sentry?如何将 4xx 错误记录到哨兵中?
【发布时间】:2021-09-09 23:03:12
【问题描述】:

目前,状态为 5xx 的服务器错误记录在哨兵中。
如何将 4xx 状态的错误记录为警告?
初始化哨兵:

Sentry.init({
  dsn: 'https://server.com/8',
  integrations: [
    new Sentry.Integrations.Http({ tracing: true }),
    new Tracing.Integrations.Express({ app: server }),
    new Tracing.Integrations.Postgres(),
    new ExtraErrorDataIntegration(),
  ],
  environment: 'ENV',
  release: 'n/a',
  tracesSampleRate: 1.0,
  enabled: true,
});

【问题讨论】:

    标签: node.js express sentry


    【解决方案1】:

    shouldHandleError 截取数据。
    在此处理程序中,您可以更改级别

    server.use(Sentry.Handlers.errorHandler({
      shouldHandleError(error) {
        if (/^[4]/.test(error.statusCode)) {
          Sentry.configureScope((scope) => {
            scope.setLevel(Sentry.Severity.Warning);
          });
        }
        return true;
      },
    }));
    

    【讨论】:

      猜你喜欢
      • 2021-06-04
      • 1970-01-01
      • 2022-01-13
      • 2021-06-13
      • 2020-01-09
      • 2014-06-11
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多