"""Application. The API application is a `flask` application. It provides simple features such as registering a url for a specific handlers. """ from flask import Flask from flask_sqlalchemy import SQLAlchemy import logging from owslogger import flask_logger from owslogger import logger from owsrequest import flask_request from product_configuration import config app = Flask(config.SERVICE_NAME) app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_CONNECTION_URL app.config['SQLALCHEMY_ENGINE_OPTIONS'] = config.SQLALCHEMY_ENGINE_OPTIONS app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.SQLALCHEMY_TRACK_MODIFICATIONS db = SQLAlchemy(app) flask_logger.setup( app, config.ENVIRONMENT, config.LOGGER_NAME, config.LOGGER_LEVEL, config.SERVICE_NAME, config.SERVICE_VERSION, exclude_paths=[config.HEALTH_CHECK], ) logger.setup( config.ENVIRONMENT, 'owsrequest', config.LOGGER_LEVEL, config.SERVICE_NAME, config.SERVICE_VERSION, ) logging.getLogger('ddtrace').setLevel(logging.WARNING) try: import uwsgi # noqa uwsgiRunning = True except ImportError: uwsgiRunning = False flask_request.setup( app, config.ENVIRONMENT, uwsgi_cache_enabled=uwsgiRunning, add_request_context=True) if config.ENVIRONMENT in [config.QA_ENVIRONMENT, config.PROD_ENVIRONMENT]: if not config.SENTRY_DSN: raise Exception(f'Sentry is not configured in {config.ENVIRONMENT}')