_should_store_errors_in_spend_logs

This commit is contained in:
Ishaan Jaff 2025-02-28 16:31:15 -08:00
parent ec7f0ce2d0
commit 7f345df477

View file

@ -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
@ -35,6 +42,9 @@ class _ProxyDBLogger(CustomLogger):
):
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,
@ -202,6 +212,26 @@ class _ProxyDBLogger(CustomLogger):
"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],