fix(budget): log warning on timezone fallback to UTC

When ZoneInfo fails to load a configured timezone (e.g. missing tzdata),
the code silently falls back to UTC. Add a verbose_logger.warning() so
operators can see which timezone failed and how to fix it.
This commit is contained in:
LeeJuOh 2026-02-22 15:41:58 +09:00
parent 6e09a52456
commit 43972a414d

View file

@ -12,6 +12,8 @@ from datetime import datetime, timedelta, timezone, tzinfo
from typing import Optional, Tuple
from zoneinfo import ZoneInfo
from litellm._logging import verbose_logger
def _extract_from_regex(duration: str) -> Tuple[int, str]:
match = re.match(r"(\d+)(mo|[smhdw]?)", duration)
@ -156,7 +158,11 @@ def _setup_timezone(
else:
tz = ZoneInfo(timezone_str)
except Exception:
# If timezone is invalid, fall back to UTC
verbose_logger.warning(
"Failed to load timezone '%s', falling back to UTC. "
"Install 'tzdata' package for full timezone support.",
timezone_str,
)
tz = timezone.utc
# Convert current_time to the target timezone