Skip to content

Commit e534cb3

Browse files
committed
Fix long S3 logging object keys
1 parent bdf4acc commit e534cb3

File tree

2 files changed

+223
-88
lines changed

2 files changed

+223
-88
lines changed

litellm/integrations/s3.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#### What this does ####
22
# On success + failure, log events to Supabase
33

4+
import hashlib
45
from datetime import datetime
56
from typing import Optional, cast
67

78
import litellm
89
from litellm._logging import print_verbose, verbose_logger
910
from litellm.types.utils import StandardLoggingPayload
1011

12+
MAX_S3_FILENAME_COMPONENT_LENGTH = 250
13+
1114

1215
class S3Logger:
1316
# Class variables or attributes
@@ -185,6 +188,11 @@ def get_s3_object_key(
185188
start_time: datetime,
186189
s3_file_name: str,
187190
) -> str:
191+
if len(s3_file_name) > MAX_S3_FILENAME_COMPONENT_LENGTH:
192+
digest = hashlib.sha256(s3_file_name.encode("utf-8")).hexdigest()[:16]
193+
prefix_length = MAX_S3_FILENAME_COMPONENT_LENGTH - len(digest) - 1
194+
s3_file_name = f"{s3_file_name[:prefix_length]}_{digest}"
195+
188196
s3_object_key = (
189197
(s3_path.rstrip("/") + "/" if s3_path else "")
190198
+ prefix

0 commit comments

Comments
 (0)