security: avoid logging sensitive data in usage dict

- Replace full usage dict logging with keys and type only

- Prevents potential exposure of sensitive information in debug logs

- Maintains debugging capability without security risk
This commit is contained in:
Alexsander Hamir 2026-01-14 12:35:31 -08:00
parent 5401e6d97b
commit 2c5048b7b6

View file

@ -4972,7 +4972,17 @@ def _try_create_usage_from_dict(usage: dict) -> Optional[Usage]:
try:
return Usage(**usage)
except (TypeError, ValueError) as e:
verbose_logger.debug(f"Error creating Usage from dict: {e}, usage: {usage}")
# Avoid logging full dict contents, which may include sensitive data
try:
usage_keys = list(usage.keys())
except Exception:
usage_keys = None
verbose_logger.debug(
"Error creating Usage from dict: %s, usage keys: %s, usage type: %s",
e,
usage_keys,
type(usage),
)
return None