"""Sentry Client. Provides sentry_client for ad hoc capturing of messages and errors. https://sentry.io/for/flask/ """ import sentry_sdk from sentry_sdk import configure_scope, utils as sentry_sdk_utils from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration sentry_client = None def init_sentry(sentry_dsn): """Init Sentry with provided DSN url.""" global sentry_client if sentry_dsn: sentry_sdk_utils.MAX_STRING_LENGTH = 2048 sentry_sdk.init( dsn=sentry_dsn, integrations=[ FlaskIntegration(transaction_style='url'), SqlalchemyIntegration(), ], ) sentry_client = sentry_sdk.client def send_to_sentry(message, errors, status, sentry_message): """Send to Sentry.""" with configure_scope() as scope: scope.set_extra('message', message) scope.set_extra('errors', errors) scope.set_extra('status', status) sentry_sdk.capture_message(sentry_message)