Skip to content

Commit

Permalink
_should_store_errors_in_spend_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-jaff committed Mar 1, 2025
1 parent ec7f0ce commit 7f345df
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion litellm/proxy/hooks/proxy_track_cost_callback.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""
_ProxyDBLogger, handles writing per request logs to the database
- track_cost_callback, stores successful requests to the database
- async_post_call_failure_hook, stores failed requests to the database
- for now this is opt in, we don't track failed requests in the DB by default
"""

import asyncio
import json
import traceback
from datetime import datetime
from typing import Any, Optional, Union, cast
Expand Down Expand Up @@ -35,6 +42,9 @@ async def async_post_call_failure_hook(
):
from litellm.proxy.proxy_server import update_database

if _ProxyDBLogger._should_store_errors_in_spend_logs() is not True:
return

_metadata = dict(
StandardLoggingUserAPIKeyMetadata(
user_api_key_hash=user_api_key_dict.api_key,
Expand Down Expand Up @@ -202,6 +212,26 @@ async def _PROXY_track_cost_callback(
"Error in tracking cost callback - %s", str(e)
)

@staticmethod
def _should_store_errors_in_spend_logs() -> bool:
"""
Returns True if we should store errors in the spend logs
Enabled when `store_errors_in_spend_logs` is set to `true` in the `general_settings` section of the config file.
By Default, this is disabled.
```yaml
general_settings:
store_errors_in_spend_logs: true
```
"""
from litellm.proxy.proxy_server import general_settings

if general_settings.get("store_errors_in_spend_logs", False) is True:
return True
return False


def _should_track_cost_callback(
user_api_key: Optional[str],
Expand Down

0 comments on commit 7f345df

Please sign in to comment.