From 6aee03f0f693f40d4ed07215d715aaddf1e2e761 Mon Sep 17 00:00:00 2001 From: Daniel Moreno Date: Tue, 17 Aug 2021 20:14:51 +0200 Subject: [PATCH] chore(tooling): configure sentry --- giges/app.py | 12 ++++++++++++ giges/settings.py | 3 +++ requirements.in | 3 ++- requirements.txt | 10 +++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/giges/app.py b/giges/app.py index dcf98d5..2b8a857 100644 --- a/giges/app.py +++ b/giges/app.py @@ -4,11 +4,13 @@ from typing import Any, Optional import connexion +import sentry_sdk import structlog from connexion.apps.flask_app import FlaskApp from connexion.resolver import RestyResolver from flask import Flask from flask_migrate import Migrate +from sentry_sdk.integrations.flask import FlaskIntegration SETTINGS_VARIABLE_NAME = "GIGES_SETTINGS" @@ -43,6 +45,15 @@ def configure_logging() -> None: ) +def configure_sentry(app: Flask) -> None: + if app.config["SENTRY_URI"]: + sentry_sdk.init( + dsn=app.config["SENTRY_URI"], + environment=app.config["ENVIRONMENT"], + integrations=[FlaskIntegration()], + ) + + def create_connexion_app( settings_object: Optional[Any] = None, **kwargs: int ) -> connexion.App: @@ -76,6 +87,7 @@ def create_connexion_app( Migrate(flask_app, db) configure_logging() + configure_sentry(flask_app) return connexion_app diff --git a/giges/settings.py b/giges/settings.py index 88df8b7..c9dd0cf 100644 --- a/giges/settings.py +++ b/giges/settings.py @@ -7,6 +7,7 @@ class BaseSettings: APP_VERSION = os.getenv("APP_VERSION", "latest") ENVIRONMENT = "" + SENTRY_URI = "" DEBUG = os.getenv("GIGES_DEBUG", "0") == "1" # Database @@ -17,6 +18,8 @@ class BaseSettings: class ProductionSettings(BaseSettings): ENVIRONMENT = "production" + SENTRY_URI = "https://ec9a91e1ce0e40f59388c665c092dc2a@o640190.ingest.sentry.io/5911249" # noqa: E501 + class StagingSettings(BaseSettings): ENVIRONMENT = "staging" diff --git a/requirements.in b/requirements.in index 1b0fabd..5da907e 100644 --- a/requirements.in +++ b/requirements.in @@ -3,10 +3,11 @@ flask-migrate flask-sqlalchemy psycopg2 zappa +sentry-sdk[flask] sqlalchemy structlog # All the package restrictions are due to zappa :( troposphere<3 flask==1.1.4 -connexion[swagger-ui]==2.7.0 \ No newline at end of file +connexion[swagger-ui]==2.7.0 diff --git a/requirements.txt b/requirements.txt index 4025cc9..dcc9cba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,8 @@ argcomplete==1.12.3 # via zappa attrs==21.2.0 # via jsonschema +blinker==1.4 + # via sentry-sdk boto3==1.18.22 # via # kappa @@ -19,7 +21,9 @@ botocore==1.21.22 # boto3 # s3transfer certifi==2021.5.30 - # via requests + # via + # requests + # sentry-sdk cfn-flip==1.2.3 # via troposphere charset-normalizer==2.0.4 @@ -45,6 +49,7 @@ flask==1.1.4 # connexion # flask-migrate # flask-sqlalchemy + # sentry-sdk flask-migrate==3.1.0 # via -r requirements.in flask-sqlalchemy==2.5.1 @@ -124,6 +129,8 @@ requests==2.26.0 # zappa s3transfer==0.5.0 # via boto3 +sentry-sdk[flask]==1.3.1 + # via -r requirements.in six==1.16.0 # via # cfn-flip @@ -158,6 +165,7 @@ urllib3==1.26.6 # via # botocore # requests + # sentry-sdk werkzeug==0.16.1 # via # flask