def register_error_handlers(app): @app.register_error_handler(OleaException) def handle_olea_exceptions(e): return jsonify({'code': e.code, 'parms': e.parms}), 409 if not app.config.get('IGNORE_ERRORS', False): sentry_sdk_init(dsn=app.config['SENTRY_DSN'], integrations=[ flask.FlaskIntegration(), sqlalchemy.SqlalchemyIntegration(), redis.RedisIntegration() ])
def configure(): """Configure Sentry logging integration for Celery. See the `official instructions for Celery integration <https://docs.sentry.io/platforms/python/celery/>`_. Notes ----- Add the API key username/pasword pair to your netrc file. """ # Catching NetrcParseError confuses sphinx. if SPHINX: # pragma: no cover return # Delayed import from .. import app scheme, netloc, *rest = urlparse(DSN) try: auth = netrc().authenticators(netloc) if not auth: raise ValueError('No netrc entry found for {}'.format(netloc)) except (NetrcParseError, OSError, ValueError): log.exception( 'Disabling Sentry integration because we could not load ' 'the username and password for %s from the netrc file', netloc) return # The "legacy" Sentry DSN requires a "public key" and a "private key", # which are transmitted as the username and password in the URL. # However, as of Sentry 9, then "private key" part is no longer required. username, _, _ = auth dsn = urlunparse((scheme, '{}@{}'.format(username, netloc), *rest)) version = 'gwcelery-{}'.format(_version.get_versions()['version']) environment = app.conf['sentry_environment'] sentry_sdk.init(dsn, environment=environment, release=version, integrations=[ celery.CeleryIntegration(), condor.CondorIntegration(), flask.FlaskIntegration(), redis.RedisIntegration(), requests.RequestsIntegration(), subprocess.SubprocessIntegration(), tornado.TornadoIntegration() ])
def register_error_handlers(app): from flask_json import json_response # - - - - - - - - - - - - - - - - - - - - - - - @app.errorhandler(BaseError) def handle_olea_exceptions(e: BaseError): return json_response(status_=e.http_code, data_=e) # - - - - - - - - - - - - - - - - - - - - - - - from sentry_sdk import init as sentry_init from sentry_sdk.integrations import flask, redis, sqlalchemy if not app.config.get('IGNORE_ERRORS', False): sentry_init(dsn=app.config['SENTRY_DSN'], integrations=[ flask.FlaskIntegration(), sqlalchemy.SqlalchemyIntegration(), redis.RedisIntegration(), ], traces_sample_rate=0.2)
# Django-Hijack HIJACK_LOGIN_REDIRECT_URL = "/" HIJACK_LOGOUT_REDIRECT_URL = reverse_lazy("admin:accounts_user_changelist") # The Admin mixin is used because we use a custom User-model. HIJACK_REGISTER_ADMIN = False # This is a CSRF-security risk. # See: http://django-hijack.readthedocs.io/en/latest/configuration/#allowing-get-method-for-hijack-views HIJACK_ALLOW_GET_REQUESTS = True # Sentry SDK SENTRY_DSN = os.getenv("SENTRY_DSN") SENTRY_SDK_INTEGRATIONS = [ django.DjangoIntegration(), redis.RedisIntegration(), ] if celery is not None: SENTRY_SDK_INTEGRATIONS.append(celery.CeleryIntegration()) if SENTRY_DSN: import sentry_sdk SENTRY_CONFIG = { "dsn": SENTRY_DSN, "release": os.getenv("VERSION_TAG", "VERSION_TAG not set"), } sentry_sdk.init( **SENTRY_CONFIG, integrations=SENTRY_SDK_INTEGRATIONS, send_default_pii=True )