-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (35 loc) · 1.13 KB
/
main.py
File metadata and controls
43 lines (35 loc) · 1.13 KB
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
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from opentelemetry.instrumentation.fastapi import ( # type: ignore[reportMissingTypeStubs]
FastAPIInstrumentor,
)
from api.dependency_container import DependencyContainer
from api.workflows.products import product_router
from common.application_environment import ApplicationEnvironment
@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncGenerator[None]:
await DependencyContainer.initialize()
yield
def add_telemetry(app: FastAPI) -> None:
FastAPIInstrumentor.instrument_app(app) # type: ignore[reportUnknownMemberType]
openapi_url = (
"/openapi.json"
if ApplicationEnvironment.get_current() != ApplicationEnvironment.PRODUCTION
else None
)
app = FastAPI(
title="Python monorepo",
version="0.1.0",
openapi_url=openapi_url,
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=False,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(product_router.router)