Реализовать уровень 4: сквозные трассы, SLO, отказы и отчёт
This commit is contained in:
@@ -7,6 +7,8 @@ from sqlalchemy.ext.asyncio import (
|
||||
)
|
||||
|
||||
from app.config import settings
|
||||
from app.advanced import ObservedSession, install_gauges
|
||||
from app.telemetry import span
|
||||
|
||||
|
||||
database_url = settings.database_url.replace(
|
||||
@@ -38,10 +40,13 @@ engine = create_async_engine(
|
||||
|
||||
SessionLocal = async_sessionmaker(
|
||||
bind=engine,
|
||||
class_=ObservedSession,
|
||||
expire_on_commit=False,
|
||||
autoflush=False,
|
||||
)
|
||||
|
||||
install_gauges(engine)
|
||||
|
||||
|
||||
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
async with SessionLocal() as session:
|
||||
@@ -50,8 +55,9 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
|
||||
async def check_database_ready() -> bool:
|
||||
try:
|
||||
async with engine.connect() as connection:
|
||||
await connection.exec_driver_sql("SELECT 1")
|
||||
with span("db.health", {"db.system": "postgresql"}):
|
||||
async with engine.connect() as connection:
|
||||
await connection.exec_driver_sql("SELECT 1")
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user