forked from phoenix/litellm-mirror
Merge pull request #5520 from BerriAI/litellm_spend_logs_trace
[Fix - Proxy] show error from /spend/tags and /spend/logs on client side
This commit is contained in:
commit
3600b1a229
1 changed files with 78 additions and 32 deletions
|
@ -1236,6 +1236,7 @@ async def global_view_spend_tags(
|
|||
-H "Authorization: Bearer sk-1234"
|
||||
```
|
||||
"""
|
||||
import traceback
|
||||
|
||||
from enterprise.utils import ui_get_spend_by_tags
|
||||
from litellm.proxy.proxy_server import prisma_client
|
||||
|
@ -1262,9 +1263,11 @@ async def global_view_spend_tags(
|
|||
|
||||
return response
|
||||
except Exception as e:
|
||||
error_trace = traceback.format_exc()
|
||||
error_str = str(e) + "\n" + error_trace
|
||||
if isinstance(e, HTTPException):
|
||||
raise ProxyException(
|
||||
message=getattr(e, "detail", f"/spend/tags Error({str(e)})"),
|
||||
message=getattr(e, "detail", f"/spend/tags Error({error_str})"),
|
||||
type="internal_error",
|
||||
param=getattr(e, "param", "None"),
|
||||
code=getattr(e, "status_code", status.HTTP_500_INTERNAL_SERVER_ERROR),
|
||||
|
@ -1272,7 +1275,7 @@ async def global_view_spend_tags(
|
|||
elif isinstance(e, ProxyException):
|
||||
raise e
|
||||
raise ProxyException(
|
||||
message="/spend/tags Error" + str(e),
|
||||
message="/spend/tags Error" + error_str,
|
||||
type="internal_error",
|
||||
param=getattr(e, "param", "None"),
|
||||
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
@ -1749,8 +1752,11 @@ async def global_spend_logs(
|
|||
|
||||
More efficient implementation of /spend/logs, by creating a view over the spend logs table.
|
||||
"""
|
||||
import traceback
|
||||
|
||||
from litellm.proxy.proxy_server import prisma_client
|
||||
|
||||
try:
|
||||
if prisma_client is None:
|
||||
raise ProxyException(
|
||||
message="Prisma Client is not initialized",
|
||||
|
@ -1774,7 +1780,25 @@ async def global_spend_logs(
|
|||
response = await prisma_client.db.query_raw(sql_query, api_key)
|
||||
|
||||
return response
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
error_trace = traceback.format_exc()
|
||||
error_str = str(e) + "\n" + error_trace
|
||||
if isinstance(e, HTTPException):
|
||||
raise ProxyException(
|
||||
message=getattr(e, "detail", f"/global/spend/logs Error({error_str})"),
|
||||
type="internal_error",
|
||||
param=getattr(e, "param", "None"),
|
||||
code=getattr(e, "status_code", status.HTTP_500_INTERNAL_SERVER_ERROR),
|
||||
)
|
||||
elif isinstance(e, ProxyException):
|
||||
raise e
|
||||
raise ProxyException(
|
||||
message="/global/spend/logs Error" + error_str,
|
||||
type="internal_error",
|
||||
param=getattr(e, "param", "None"),
|
||||
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
|
@ -1789,8 +1813,12 @@ async def global_spend():
|
|||
|
||||
View total spend across all proxy keys
|
||||
"""
|
||||
import traceback
|
||||
|
||||
from litellm.proxy.proxy_server import prisma_client
|
||||
|
||||
try:
|
||||
|
||||
total_spend = 0.0
|
||||
total_proxy_budget = 0.0
|
||||
|
||||
|
@ -1803,6 +1831,24 @@ async def global_spend():
|
|||
total_spend = response[0].get("total_spend", 0.0)
|
||||
|
||||
return {"spend": total_spend, "max_budget": litellm.max_budget}
|
||||
except Exception as e:
|
||||
error_trace = traceback.format_exc()
|
||||
error_str = str(e) + "\n" + error_trace
|
||||
if isinstance(e, HTTPException):
|
||||
raise ProxyException(
|
||||
message=getattr(e, "detail", f"/global/spend Error({error_str})"),
|
||||
type="internal_error",
|
||||
param=getattr(e, "param", "None"),
|
||||
code=getattr(e, "status_code", status.HTTP_500_INTERNAL_SERVER_ERROR),
|
||||
)
|
||||
elif isinstance(e, ProxyException):
|
||||
raise e
|
||||
raise ProxyException(
|
||||
message="/global/spend Error" + error_str,
|
||||
type="internal_error",
|
||||
param=getattr(e, "param", "None"),
|
||||
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue