Problem:
I am trying to call a static method from a class method which throws an error. What is the right way to call that method in Python 3.x?
NameError: name 'strip_sensitive_data' is not defined
Code:
import sentry_sdk
from scrapy.exceptions import NotConfigured
class SentryLogging(object):
"""
Send exceptions and errors to Sentry.
"""
def strip_sensitive_data(event, hint):
if event['level'] == 'error':
return event
else:
return None
@classmethod
def from_crawler(cls, crawler):
sentry_dsn = crawler.settings.get('SENTRY_DSN', None)
environment = crawler.settings.get('ENVIRONMENT', None)
if sentry_dsn is None:
raise NotConfigured
# instantiate the extension object
ext = cls()
# instantiate
sentry_sdk.init(
sentry_dsn,
traces_sample_rate=1.0,
environment= environment,
before_send=strip_sensitive_data
)
# return the extension object
return ext