-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
57 lines (44 loc) · 1.39 KB
/
app.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
47
48
49
50
51
52
53
54
55
56
57
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from api import auth, heartbeat, setting, summary, user
from otp import trace, tracer
app = FastAPI()
app.include_router(auth.router, prefix="/api")
app.include_router(user.router, prefix="/api")
app.include_router(heartbeat.router, prefix="/api")
app.include_router(setting.router, prefix="/api")
app.include_router(summary.router, prefix="/api")
# app.include_router(me.router, prefix="/api")
origins = ["http://localhost", "chrome-extension://mohpaadocnhngkhlkcjimmiaidpbebbj"]
methods = [
"DELETE",
"GET",
"POST",
"PUT",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=methods,
allow_headers=["*"],
)
@trace("connect_database", test_attr="test_value")
# async def connect_db():
# try:
# await deps.get_db()
# except Exception as e:
# print(e)
@app.on_event("startup")
async def startup():
with tracer.start_as_current_span("startup_span") as span:
print("startup")
# await connect_db()
# async with engine.begin() as conn:
# await conn.run_sync(Base.metadata.create_all)
# @app.on_event("shutdown")
# async def shutdown():
# if database.is_connected:
# await database.disconnect()
FastAPIInstrumentor.instrument_app(app)