"""Sentry Client. Provides sentry_client attribute for ad hoc capturing of messages and errors. https://docs.sentry.io/platforms/python/integrations/flask/ """ import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration from analytics import config class _Client: """Shim preserving the raven.Client call surface.""" def captureException(self): sentry_sdk.capture_exception() def captureMessage(self, message, **kwargs): extras = kwargs.get('extra', {}) with sentry_sdk.push_scope() as scope: if isinstance(extras, dict): for key, value in extras.items(): scope.set_extra(key, value) sentry_sdk.capture_message(message) sentry_sdk.init( dsn=config.SENTRY or '', release=config.CURRENT_COMMIT_HASH, integrations=[FlaskIntegration()], ) sentry_client = _Client()