Why does this logger not create Sentry events?

Viewed 4376

I'm using django and sentry-sdk. In my django settings' logger section I have the following handler:

'loggers': {
    'django.request': {
        'level': 'WARNING',                                     
        'handlers': ['console', ],                    
        'propagate': False
    }
}

And the sentry-sdk is initialized as follows:

import logging                                                                    
import sentry_sdk                                                                 
from sentry_sdk.integrations.django import DjangoIntegration                      
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_logging = LoggingIntegration(                                              
    level=logging.INFO,
    event_level=logging.ERROR
)                                                                                 
sentry_sdk.init(                                                                  
    dsn="...",              
    integrations=[DjangoIntegration(), sentry_logging],                           
)                                                                                 

However, the following example does not send an error event to sentry

import logging
logger = logging.getLogger('django.request')
logger.error('Why do I not appear in sentry?')

On the other hand, others do, as for example

import logging
logger = logging.getLogger('another_module')
logger.error('And why do I do appear in sentry?')

Question: How can I fix this for modules with propagate=False?

2 Answers

Generally speaking there are three ways I can think of that a log message can not turn out as event:

  • The event_level parameter is set too high (error by default, do init(integrations=[LoggingIntegration(event_level=logging.DEBUG)])
  • Your logger's level is too high (do logger.setLevel(logging.DEBUG))
  • Your logger has a filter that filters out these messages (check logger.filters for emptyness)

In your case I can only think of the latter case applying.

Related