How to ignore a logger in the Sentry Python SDK
Under the sentry_sdk I had to use the following code in before_send to get it to ignore the django.security.DisallowedHost exception.
def before_send(event, hint):
"""Don't log django.DisallowedHost errors in Sentry."""
if 'log_record' in hint:
if hint['log_record'].name == 'django.security.DisallowedHost':
return None
return event
Quick answer
See LoggingIntegration, eg:
from sentry_sdk.integrations.logging import ignore_logger
ignore_logger("a.spammy.logger")
logger = logging.getLogger("a.spammy.logger")
logger.error("hi") # no error sent to sentry
A more elaborate but generic way to ignore events by certain characteristics
See before_breadcrumb and before_send, eg:
import sentry_sdk
def before_breadcrumb(crumb, hint):
if crumb.get('category', None) == 'a.spammy.Logger':
return None
return crumb
def before_send(event, hint):
if event.get('logger', None) == 'a.spammy.Logger':
return None
return event
sentry_sdk.init(before_breadcrumb=before_breadcrumb, before_send=before_send)