Django-sentry does not record warnings, errors, etc.

I just installed django-sentry and it catches exceptions perfectly. However, the calls to logger.warning and logger.error for some reason are not stored in Sentry.

Sentry:

import logging from sentry.client.handlers import SentryHandler logger = logging.getLogger() # ensure we havent already registered the handler if SentryHandler not in map(lambda x: x.__class__, logger.handlers): logger.addHandler(SentryHandler()) # Add StreamHandler to sentry default so you can catch missed exceptions logger = logging.getLogger('sentry.errors') logger.propagate = False logger.addHandler(logging.StreamHandler()) 

logger call:

 logger.warning("Category is not an integer", exc_info=sys.exc_info(), extra={'url': request.build_absolute_uri()}) 

Any ideas? Thanks!

+6
source share
3 answers

Try adding:

logger.setLevel (logging.DEBUG)

after logging.getlogger, it works for me on dev env.

+3
source

You attach a descriptor handler to logging.getLogger('sentry.errors') . This means logs to sentry.errors or lower, which the handler of this stream will use.

But the logs before 'my_app.something' don't end there! This way you skip almost all the log messages.

Solution: attach the stream handler to the root logger: logging.getLogger('') .

+3
source

You can add a FileHandler to the 'sentry.errors' logger and check if it contains some production error. But actually stdout should be written to server logs. You can check it out.

0
source

Source: https://habr.com/ru/post/886446/


All Articles