我有一个使用Sentry进行异常跟踪的Spring Boot应用程序,我收到的错误如下所示:
ClientAbortExceptionorg.apache.catalina.connector.OutputBuffer in realWriteBytes
errorjava.io.IOException: Broken pipe
我的理解是它只是一个网络错误,因此我通常应该忽略它们。我想要做的是报告所有其他IOExceptions
并将破损的管道记录到Librato,这样我就可以关注我得到了多少(一个尖峰可能意味着客户端存在问题) ,这也是我用Java开发的):
我想出了这个:
@ControllerAdvice
@Priority(1)
@Order(1)
public class RestExceptionHandler {
@ExceptionHandler(ClientAbortException.class)
@ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
public ResponseEntity<?> handleClientAbortException(ClientAbortException ex, HttpServletRequest request) {
Throwable rootCause = ex;
while (ex.getCause() != null) {
rootCause = ex.getCause();
}
if (rootCause.getMessage().contains("Broken pipe")) {
logger.info("count#broken_pipe=1");
} else {
Sentry.getStoredClient().sendException(ex);
}
return null;
}
}
这是解决这个问题的可接受方式吗?
我按照文档的方式配置了Sentry:
@Configuration
public class FactoryBeanAppConfig {
@Bean
public HandlerExceptionResolver sentryExceptionResolver() {
return new SentryExceptionResolver();
}
@Bean
public ServletContextInitializer sentryServletContextInitializer() {
return new SentryServletContextInitializer();
}
}