除了报告给哨兵之外,不包括某些例外



基于弹簧靴的Web服务正在使用文档中所述的哨兵。它可以正常工作,但是不应将一些例外发送到哨兵,例如为了在某些请求中返回HTTP状态410,引发了一个例外:

// Kotlin code, but in Java it would be similar.
@ResponseStatus(value = HttpStatus.GONE)
class GoneException(msg: String) : RuntimeException(msg) {
}

如何告诉我的sentryExceptionResolver跳过这些例外?

在Python中,很简单您只需在配置文件中添加以下代码即可忽略多个异常

ignore_exceptions = [
    'Http404',
    'Http401'
    'django.exceptions.http.Http404',
    'django.exceptions.*',
    ValueError,
]

但是在Java中,我找不到sentry.properties中的类似标签,尝试一下,也许您会找到它。

##Just give it a try, I didnt test    
ignore.exceptions:
        HTTP 401

您可以在配置类中添加HandlerExceptionResolver并覆盖resolveException()方法,而手动忽略异常:

@Configuration
public class FactoryBeanAppConfig {
    @Bean
    public HandlerExceptionResolver sentryExceptionResolver() {
        return new SentryExceptionResolver() {
            @Override
            public ModelAndView resolveException(HttpServletRequest request,
                    HttpServletResponse response,
                    Object handler,
                    Exception ex) {
                Throwable rootCause = ex;
                while (rootCause .getCause() != null && rootCause.getCause() != rootCause) {
                    rootCause = rootCause.getCause();
                }
                if (!rootCause.getMessage().contains("HTTP 401")) {
                    super.resolveException(request, response, handler, ex);
                }
                return null;
            }   
        };
    }
    @Bean
    public ServletContextInitializer sentryServletContextInitializer() {
        return new SentryServletContextInitializer();
    }
}

您可以设置;

ignored-exceptions-for-type=java.lang.RuntimeException,java.lang.IllegalStateException

https://docs.sentry.io/platforms/java/configuration/

相关内容

  • 没有找到相关文章

最新更新