File size: 713 Bytes
0a8c81b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from sqlmodel import SQLModel, create_engine, Session
from sqlalchemy.dialects import registry
from src.core.config import settings

# Register the libsql dialect manually to bypass uvicorn/uv entry_points cache issues on Hugging Face
registry.register("sqlite.libsql", "sqlalchemy_libsql.libsql", "SQLiteDialect_libsql")

from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor

engine = create_engine(
    settings.get_sqlalchemy_url, 
    echo=True, 
    connect_args=settings.get_sqlalchemy_connect_args
)

# Instrument the database engine for tracing
SQLAlchemyInstrumentor().instrument(
    engine=engine,
)

def get_session():
    with Session(engine) as session:
        yield session