From 79bdbd2506469e5eacc95885db052317c528b3df Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Mon, 9 Feb 2026 17:46:54 -0800 Subject: [PATCH] perf(log_db_metrics): fast path in _is_exception_related_to_db to avoid Prisma import Check exception module (prisma/httpx) before importing Prisma, which is expensive on first load (~12s). Non-DB exceptions return False without import. --- litellm/proxy/db/log_db_metrics.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/db/log_db_metrics.py b/litellm/proxy/db/log_db_metrics.py index 5c795155324..33e45291ee3 100644 --- a/litellm/proxy/db/log_db_metrics.py +++ b/litellm/proxy/db/log_db_metrics.py @@ -103,9 +103,15 @@ def log_db_metrics(func): def _is_exception_related_to_db(e: Exception) -> bool: """ - Returns True if the exception is related to the DB + Returns True if the exception is related to the DB (PrismaError, httpx connection/timeout). + Uses a fast path: if the exception is not from prisma or httpx modules, return False + without importing Prisma (which is expensive ~12s on first load). """ + mod = type(e).__module__ + if not (mod.startswith("prisma") or mod.startswith("httpx")): + return False + import httpx from prisma.errors import PrismaError