Skip to content

Commit

Permalink
Intercept exceptions with sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
LoanR committed May 28, 2024
1 parent fbb6b84 commit c3d4995
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 16 deletions.
56 changes: 52 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sqlalchemy = "^1.4.31"
sqlalchemy-json = "^0.7.0"
sqlalchemy-utils = "^0.41.1"
webdavclient3 = "3.14.6"
sentry-sdk = "^2.3.1"

[tool.poetry.group.dev]
optional = true
Expand Down
45 changes: 33 additions & 12 deletions web/b3desk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ def setup_cache(app):
cache.init_app(app, config=config)


def setup_sentry(app): # pragma: no cover
if not app.config.get("SENTRY_DSN"):
return None

try:
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

except Exception:
return None

sentry_sdk.init(dsn=app.config["SENTRY_DSN"], integrations=[FlaskIntegration()])
return sentry_sdk


def setup_logging(app):
if not app.debug and not app.testing:
dictConfig(
Expand Down Expand Up @@ -257,18 +272,24 @@ def setup_oidc(app):

def create_app(test_config=None):
app = Flask(__name__)
setup_configuration(app, test_config)
setup_celery(app)
setup_cache(app)
setup_logging(app)
setup_i18n(app)
setup_csrf(app)
setup_database(app)
setup_jinja(app)
setup_flask(app)
setup_error_pages(app)
setup_endpoints(app)
setup_oidc(app)
sentry_sdk = setup_sentry(app)
try:
setup_configuration(app, test_config)
setup_celery(app)
setup_cache(app)
setup_logging(app)
setup_i18n(app)
setup_csrf(app)
setup_database(app)
setup_jinja(app)
setup_flask(app)
setup_error_pages(app)
setup_endpoints(app)
setup_oidc(app)
except Exception as exc: # pragma: no cover
if sentry_sdk:
sentry_sdk.capture_exception(exc)
raise

# ensure the instance folder exists
os.makedirs(app.instance_path, exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions web/requirements.app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ python-slugify==8.0.4 ; python_version >= "3.9" and python_version < "4.0"
pytz==2024.1 ; python_version >= "3.9" and python_version < "4.0"
redis==5.0.4 ; python_version >= "3.9" and python_version < "4.0"
requests==2.31.0 ; python_version >= "3.9" and python_version < "4.0"
sentry-sdk==2.3.1 ; python_version >= "3.9" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.9" and python_version < "4.0"
sqlalchemy-json==0.7.0 ; python_version >= "3.9" and python_version < "4.0"
sqlalchemy-utils==0.41.2 ; python_version >= "3.9" and python_version < "4.0"
Expand Down

0 comments on commit c3d4995

Please sign in to comment.