-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (34 loc) · 1.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from datetime import datetime
from fastapi import FastAPI
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from pydantic.json import ENCODERS_BY_TYPE
from app import exception, shutdown, startup
from app.api import middleware, route
from app.core.configs.app_config import app_config
from app.core.data.data_response import DataResponse
from app.core.logs.logging_setup import get_logger
from app.core.utils.date_util import to_epoch
# Override datetime encoder for the json response
ENCODERS_BY_TYPE[datetime] = to_epoch
_app_config = app_config()
logger = get_logger(__name__)
def create_app() -> FastAPI:
logger.info(f"Running in {_app_config.environment} environment")
# App instance
application = FastAPI(
title=_app_config.name,
version=_app_config.version,
default_response_class=DataResponse,
)
startup.add_handlers(application)
shutdown.add_handlers(application)
middleware.add_middlewares(application)
exception.add_handlers(application)
route.include_routers(application)
FastAPIInstrumentor.instrument_app(
application,
excluded_urls="healthcheck,metrics"
)
return application
# Create an instance of the app
app = create_app()