I use Sentry for inspecting the errors. In one part of my code, there's a try/except block for a snippet that uses langdetect and throws a LangDetectException. That code looks like
try:
return detect(text)
except LangDetectException as error:
logging.error(repr(error))
Well I don't really understand the docs from Sentry about whether they should log errors in except scope or log only unhandled errors? In one place, they say that Sentry shouldn't log caught errors on other it says it should so I'm a little bit confused. The mentioned code, when text was made only from non-alpha chars, threw the LangDetectException('No features in text.') error but also listed it on Sentry as an error. Why does this happen? Obviously, this is a caught error and I want to have it only logged in my logs and not in Sentry. Is this a normal behavior for Sentry or there's something I'm missing?
Creating an official answer. I just ran into this also. @zoran404's comment is correct.
The Python Sentry package will create an issue for logging.error() calls by default.
Calling sentry_sdk.init() already integrates with the logging module. It is equivalent to this explicit configuration:
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
)
from https://docs.sentry.io/platforms/python/guides/logging/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With