Saturnix
Saturnix

Reputation: 10554

Sentry DjangoIntegration event_level

I'm using Sentry with Django like this:

sentry_integration = DjangoIntegration()
sentry_sdk.init(
    dsn="https://[email protected]/xxx",
    integrations=[sentry_integration]
)

and with these settings for logging:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
        'file': {
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_DIR, 'logs', 'django.log'),
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file', 'console'],
            'level': 'DEBUG',
        },
        'django.template': {
            'handlers': ['file', 'console'],
            'level': 'INFO',
        },
        'app': {
            'handlers': ['file', 'console'],
            'level': 'DEBUG',
        }
    },
}

If I instiantiate and call a logger in my code, this gets sent to Sentry.

import logging
logger = logging.getLogger(__name__)

logger.error("error!")

However, now I'd like to also log .warning calls. The documentation says to do this:

sentry_logging = LoggingIntegration(event_level=logging.WARNING)
sentry_sdk.init(
    dsn="https://[email protected]/xxx",
    integrations=[sentry_logging]
)

But the LoggingIntegration is used rather than the DjangoIntegration. I've tried to use DjangoIntegration in the code above but I get this error:

TypeError: init() got an unexpected keyword argument 'event_level'

Is this possible?

Upvotes: 0

Views: 245

Answers (1)

Markus Unterwaditzer
Markus Unterwaditzer

Reputation: 8244

The integrations argument is a list. You can pass in both integrations:

init(
    integrations=[LoggingIntegration(...), DjangoIntegration(...)]
)

Upvotes: 1

Related Questions