为什么Sentry会记录除块中捕获的错误



我使用Sentry来检查错误。在我的代码的一部分中,有一个try/except块用于使用langdetect并抛出LangDetectException的代码段。那个代码看起来像

try:
return detect(text)
except LangDetectException as error:
logging.error(repr(error))

我真的不理解Sentry的文档,他们是应该在except范围内记录错误,还是只记录未处理的错误?在一个地方,他们说哨兵不应该在另一个地方记录捕捉到的错误,它说应该这样做,所以我有点困惑。当文本仅由非阿尔法字符组成时,上述代码抛出了LangDetectException('No features in text.')错误,但也在Sentry上将其列为错误。为什么会发生这种情况?显然,这是一个被捕获的错误,我只想把它记录在我的日志中,而不是Sentry中。这是哨兵的正常行为还是我遗漏了什么?

创建正式答案。我刚刚也碰到了这个@zoran404的评论是正确的。

Python Sentry包默认情况下会为logging.error((调用创建一个问题。

调用sentry_sdk.int((已经与日志记录模块集成。它相当于这个显式配置:

import logging
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
# All of this is already happening by default!
sentry_logging = LoggingIntegration(
level=logging.INFO,        # Capture info and above as breadcrumbs
event_level=logging.ERROR  # Send errors as events
)

来自https://docs.sentry.io/platforms/python/guides/logging/

最新更新