storage-service/storage_service/app.py
marcsello 01d7c76cff
Some checks failed
continuous-integration/drone/push Build is failing
Logging stuff
2021-08-09 15:48:19 +02:00

68 lines
1.8 KiB
Python

#!/usr/bin/env python3
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix
from healthcheck import HealthCheck
# import stuff
from utils import register_all_error_handlers, storage, health_database_status
# import views
from views import ObjectView
from config import Config
# Setup sentry
if Config.SENTRY_DSN:
sentry_sdk.init(
dsn=Config.SENTRY_DSN,
integrations=[FlaskIntegration()],
_experiments={"auto_enabling_integrations": True},
traces_sample_rate=0,
send_default_pii=True,
release=Config.RELEASE_ID,
environment=Config.RELEASEMODE
)
# create flask app
app = Flask(__name__)
app.config.from_object(Config)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
# init stuff
storage.init_app(app)
health = HealthCheck()
# register error handlers
register_all_error_handlers(app)
# register views
for view in [ObjectView]:
view.register(app, trailing_slash=False)
health.add_check(health_database_status)
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
# start debugging if needed
if __name__ == "__main__":
app.run(debug=True)
else:
import os
if "gunicorn" in os.environ.get("SERVER_SOFTWARE", ""):
import logging
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
jaeger_logger = logging.getLogger('jaeger_tracing')
jaeger_logger.handlers = gunicorn_logger.handlers
jaeger_logger.setLevel(gunicorn_logger.level)
app.logger.info("Gunicorn environment detected!")
else:
app.logger.info("Not gunicorn")