Python_sdk not triggering event on logging level INFO

I’m trying to switch from raven to the Sentry python_sdk. Sending errors is working as expected, but it is not sending events for logs of the INFO level. I already changed the event_level of the LoggingIntegration to logging.INFO:

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

def before_send(event, hint):
    if "exc_info" in hint:
        exc_type, exc_value, tb = hint["exc_info"]
        if isinstance(exc_value, KeyboardInterrupt):
            return None

    return event

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

I also attached the sentry handler which I can also retrieve from the logger. The Level is INFO as well. The logger of concern is called MyLogger as stated with the variable LOGGER_NAME.

LOGGER_NAME = "MyLogger"
LOGGING = {
    "version": 1,
    "disable_existing_loggers": True,
    "formatters": {"verbose": {"format": "%(levelname)s %(asctime)s %(module)s " "%(process)d %(thread)d %(message)s"}},
    "handlers": {
        "sentry": {
            "level": "INFO",
            "class": "sentry_sdk.integrations.logging.EventHandler",
        },
        "console": {"level": "DEBUG", "class": "logging.StreamHandler", "formatter": "verbose"},
    },
    "loggers": {
        "django": {"propagate": False, "handlers": ["sentry", "console"]},
        "django.request": {"level": "ERROR", "propagate": False, "handlers": ["sentry", "console"]},
        "django.db.backends": {"level": "ERROR", "propagate": False, "handlers": ["sentry", "console"]},
        "raven": {"level": "WARNING", "propagate": False, "handlers": ["sentry", "console"]},
        "sentry.errors": {"level": "WARNING", "propagate": False, "handlers": ["sentry", "console"]},
        LOGGER_NAME: {"level": "INFO", "propagate": False, "handlers": ["sentry"]},
        "{}.test".format(LOGGER_NAME): {"level": "INFO", "propagate": False, "handlers": ["console"]},
    },
}

Does anyone have an idea how I can make this work?

Hi, what is the actual name of the logger?

Hi, thanks for answering!
The logger I’m retrieving is the LOGGER_NAME= "MyLogger".

I see, reason I’m asking is because we ignore some Django loggers explicitly. Did you happen to use a special transport in Raven?

What do you exactly with special transport?

For example if you use the synchronous/blocking or the gevent transport as documented here: https://docs.sentry.io/clients/python/transports/

I see. No, I don’t use it.

Hmm. Could you init(debug=True) and check if you see anything in the logs?

Note that I integrated sentry in Django. After activating the debug Flag, I get the following messages:

 [sentry] DEBUG: Setting up previously not enabled integration django
 [sentry] DEBUG: Setting up previously not enabled integration logging
 [sentry] DEBUG: Setting up previously not enabled integration stdlib
 [sentry] DEBUG: Setting up previously not enabled integration excepthook
 [sentry] DEBUG: Setting up previously not enabled integration dedupe
 [sentry] DEBUG: Setting up previously not enabled integration atexit
 [sentry] DEBUG: Setting up previously not enabled integration modules
 [sentry] DEBUG: Setting up previously not enabled integration argv
 [sentry] DEBUG: Setting up previously not enabled integration threading
 [sentry] DEBUG: Enabling integration django
 [sentry] DEBUG: Enabling integration logging
 [sentry] DEBUG: Enabling integration stdlib
 [sentry] DEBUG: Enabling integration excepthook
 [sentry] DEBUG: Enabling integration dedupe
 [sentry] DEBUG: Enabling integration atexit
 [sentry] DEBUG: Enabling integration modules
 [sentry] DEBUG: Enabling integration argv
 [sentry] DEBUG: Enabling integration threading

When I execute the following:

logger = logging.getLogger("MyLogger")
logger.info("test")
logger.error("test")

The .error function is triggering an event while the .info function does not.

@mpanzirsch The only explanation I have is that your logging config does not actually get applied. Could you print out logger.level and logger.handlers?

@untitaker Sorry for the confusion. Seems like the problem lies not in the python sdk but in a wrapping function I am using. The logging level and handlers are correct as well. Therefore we can close this issue. Thank you for your time!

1 Like

Just to describe the problem:
I passed the default value False for exc_info to the .log function of the logger which prevents the event to be triggered. This seems to be an uncovered case in the ._log function which is called in .log.