(fix) high traffic langfuse, s3

This commit is contained in:
ishaan-jaff 2024-03-06 12:22:52 -08:00
parent 74e50d9d35
commit c4079b2548
2 changed files with 18 additions and 4 deletions

View file

@ -285,9 +285,6 @@ class LangFuseLogger:
if key in [ if key in [
"headers", "headers",
"endpoint", "endpoint",
"model_group",
"deployment",
"model_info",
"caching_groups", "caching_groups",
"previous_models", "previous_models",
]: ]:

View file

@ -104,6 +104,23 @@ class S3Logger:
usage = response_obj["usage"] usage = response_obj["usage"]
id = response_obj.get("id", str(uuid.uuid4())) id = response_obj.get("id", str(uuid.uuid4()))
# Clean Metadata before logging - never log raw metadata
# the raw metadata can contain circular references which leads to infinite recursion
# we clean out all extra litellm metadata params before logging
clean_metadata = {}
if isinstance(metadata, dict):
for key, value in metadata.items():
# clean litellm metadata before logging
if key in [
"headers",
"endpoint",
"caching_groups",
"previous_models",
]:
continue
else:
clean_metadata[key] = value
# Build the initial payload # Build the initial payload
payload = { payload = {
"id": id, "id": id,
@ -117,7 +134,7 @@ class S3Logger:
"messages": messages, "messages": messages,
"response": response_obj, "response": response_obj,
"usage": usage, "usage": usage,
"metadata": metadata, "metadata": clean_metadata,
} }
# Ensure everything in the payload is converted to str # Ensure everything in the payload is converted to str