litellm/tests/_support/native_database.py
yujonglee bd27f4e34c
feat(db): emit DB service events from native operations (#49810)
crates/db gains observe(), which records one event per round trip with the
call type, table and operation a Prisma call reports. NativeDatabase forwards
those events to a Python ServiceLoggingEvents that Database.open injects, and
it calls the same ServiceTypes.DB success and failure hooks as db_span on the
proxy's event loop. A native health_check, which pings one pooled connection
without running SQL (call type health_check), is the first observed operation

The native pool is lazy, so a pool that could not connect stayed silent until
the first ported query failed on a request path. Database.open now pings it
once in the background and logs a warning on failure, without failing or
delaying boot

The crate AGENTS.md records the Prometheus and OTel names a Rust host sink must match
2026-11-14 15:28:10 -08:00

19 lines
653 B
Python

import asyncio
from typing import Final
from litellm.proxy.db.native_database import ServiceLoggingEvents, native_endpoint
from litellm.rust_bridge._native import NativeDatabase
_NEVER_DIALED_URL: Final = "postgresql://litellm:secret@db.invalid:5432/proxy"
async def connect_native_database() -> NativeDatabase:
return await NativeDatabase.connect(
ServiceLoggingEvents(loop=asyncio.get_running_loop(), service_logging=lambda: None),
native_endpoint(_NEVER_DIALED_URL, tls_offered=True, max_connections=1).endpoint,
None,
)
def native_database() -> NativeDatabase:
return asyncio.run(connect_native_database())