当我的数据库出现故障时,Sentry 立即被 psycopg2 的OperationalError: could not connect to server: Connection refused
. 由于OperationalError
可以在无法访问的数据库之外的其他情况下抛出,所以我不能盲目地使用RAVEN_CONFIG
's忽略它IGNORE_EXCEPTIONS
。
我试图为 Django logging 编写一个过滤器,但它不起作用。它正确地拦截了异常,但仍然以某种方式将其冒泡。这是过滤器:
def skip_unreachable_database(record):
"""Avoid flooding Sentry when the database is down"""
if record.exc_info:
print '>>>', record.exc_info
exc_type, exc_value = record.exc_info[:2]
if isinstance(exc_value, OperationalError) and exc_value.message.lower().startswith('could not connect to server: connection refused'):
return False
return True
有一张关于过滤不适用于 Raven 的票,但它已被关闭。
知道如何解决这个问题吗?