I'm using sentry-python
SDK for capture exceptions from my django server.
I don't want to capture django.security.DisallowedHost
like above.
How to remove sentry handling for that logger?
I attached my server configuration below.
settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
},
'loggers': {
# Silence SuspiciousOperation.DisallowedHost exception ('Invalid
# HTTP_HOST' header messages). Set the handler to 'null' so we don't
# get those annoying emails.
'django.security.DisallowedHost': {
'handlers': ['null'],
'propagate': False,
},
}
}
sentry_sdk.init(
dsn=os.environ['SENTRY_DSN'],
integrations=[DjangoIntegration()],
send_default_pii=True,
release=f"{os.environ['STAGE']}@{os.environ['VERSION']}",
)
Quick answer
https://docs.sentry.io/platforms/python/logging/#ignoring-a-logger
A more elaborate but generic way to ignore events by certain characteristics
See https://docs.sentry.io/learn/breadcrumbs/?platform=python#breadcrumb-customization
Under the sentry_sdk I had to use the following code in before_send to get it to ignore the django.security.DisallowedHost exception.