birb-scheduler-teller/birb_scheduler_teller/app.py
marcsello d0d017a4f7
All checks were successful
continuous-integration/drone/push Build is passing
aaa
2021-12-10 23:51:00 +01:00

83 lines
2.1 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
# import stuff
from utils import register_all_error_handlers, register_health_checks, redis_client
# import views
from views import AssignmentView
from config import Config
# Tracing stuffs
import jaeger_client
import opentracing
from flask_opentracing import FlaskTracing
# Setup sentry
if Config.SENTRY_DSN:
sentry_sdk.init(
dsn=Config.SENTRY_DSN,
integrations=[FlaskIntegration()],
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
redis_client.init_app(app)
# register error handlers
register_all_error_handlers(app)
# Setup tracing
def initialize_tracer():
app.logger.info("Initializing jaeger...")
jaeger_cfg = jaeger_client.Config(config={}, service_name='birb-scheduler-teller', validate=True)
tracer = jaeger_cfg.initialize_tracer()
return tracer
tracing = FlaskTracing(initialize_tracer, True, app)
# register views
for view in [AssignmentView]:
view.register(app, trailing_slash=False)
register_health_checks(app)
# start debugging if needed
if __name__ == "__main__":
app.logger.info(f"Hard default: {Config.DEFAULT_WHILE_NOT_DEFINED}")
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")
app.logger.info(f"Hard default: {Config.DEFAULT_WHILE_NOT_DEFINED}")