某些情况下我们希望sentry不要上报logger数据。比如错误已经上报,而通过logger.error写入日志的数据也会上报,导致重复。
有两种方式:
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
def before_send(event, hint):
if event.get('logger', None) == 'a.spammy.Logger':
return None
return event
sentry_sdk.init(before_send=before_send)
以上两种方式均验证通过
但stackoverflow中的before_breadcrumb没有验证通过,如果有清楚的还望不吝赐教。
参考:
https://stackoverflow.com/a/52937429/7151777
https://docs.sentry.io/platforms/python/guides/logging/#ignoring-a-logger
https://docs.sentry.io/platforms/python/guides/logging/configuration/filtering/#using-beforesend