Skip to content

Commit b7ba96a

Browse files
committed
Add telemetry
1 parent ae9eba3 commit b7ba96a

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed

api/src/api/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
3+
from opentelemetry.instrumentation.fastapi import ( # type: ignore[reportMissingTypeStubs]
4+
FastAPIInstrumentor,
5+
)
26

37
from api.dependency_container import DependencyContainer
48
from api.workflows.products import product_router
59
from common.application_environment import ApplicationEnvironment
610

11+
12+
def add_telemetry(app: FastAPI) -> None:
13+
FastAPIInstrumentor.instrument_app(app) # type: ignore[reportUnknownMemberType]
14+
15+
716
DependencyContainer.initialize()
817
openapi_url = (
918
"/openapi.json"
1019
if ApplicationEnvironment.get_current() != ApplicationEnvironment.PRODUCTION
1120
else None
1221
)
1322
app = FastAPI(title="Python monorepo", version="0.1.0", openapi_url=openapi_url)
23+
app.add_middleware(
24+
CORSMiddleware,
25+
allow_origins=["*"],
26+
allow_credentials=False,
27+
allow_methods=["*"],
28+
allow_headers=["*"],
29+
)
1430
app.include_router(product_router.router)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"common",
99
"domain",
1010
"fastapi[standard]==0.115.12",
11+
"opentelemetry-instrumentation-fastapi==0.54b1",
1112
"poethepoet==0.34.0",
1213
"pydantic==2.11.4",
1314
"pydantic-settings[azure-key-vault]==2.9.1",

0 commit comments

Comments
 (0)