Changeset View
Changeset View
Standalone View
Standalone View
swh/core/sentry.py
Show All 10 Lines | def get_sentry_release(): | ||||
main_package = os.environ.get('SWH_MAIN_PACKAGE') | main_package = os.environ.get('SWH_MAIN_PACKAGE') | ||||
if main_package: | if main_package: | ||||
version = pkg_resources.get_distribution(main_package).version | version = pkg_resources.get_distribution(main_package).version | ||||
return f'{main_package}@{version}' | return f'{main_package}@{version}' | ||||
else: | else: | ||||
return None | return None | ||||
def init_sentry( | def init_sentry(sentry_dsn, *, debug=None, integrations=[], extra_kwargs={}): | ||||
sentry_dsn, *, debug=None, integrations=[], | |||||
extra_kwargs={}): | |||||
if debug is None: | if debug is None: | ||||
debug = bool(os.environ.get('SWH_SENTRY_DEBUG')) | debug = bool(os.environ.get('SWH_SENTRY_DEBUG')) | ||||
sentry_dsn = sentry_dsn or os.environ.get('SWH_SENTRY_DSN') | sentry_dsn = sentry_dsn or os.environ.get('SWH_SENTRY_DSN') | ||||
environment = os.environ.get('SWH_SENTRY_ENVIRONMENT') | environment = os.environ.get('SWH_SENTRY_ENVIRONMENT') | ||||
if sentry_dsn: | if sentry_dsn: | ||||
import sentry_sdk | import sentry_sdk | ||||
sentry_sdk.init( | sentry_sdk.init( | ||||
release=get_sentry_release(), | release=get_sentry_release(), | ||||
environment=environment, | environment=environment, | ||||
dsn=sentry_dsn, | dsn=sentry_dsn, | ||||
integrations=integrations, | integrations=integrations, | ||||
debug=debug, | debug=debug, | ||||
**extra_kwargs, | **extra_kwargs, | ||||
) | ) |