From 853b70aba98f59433b7095ef71e07cd3df8bb060 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 29 Apr 2024 16:39:01 -0700 Subject: [PATCH] fix(langfuse.py): support 'existing_trace_id' param allow user to call out a trace as pre-existing, this prevents creating a default trace name, and potentially overwriting past traces --- litellm/integrations/langfuse.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 063b675d42..b1c0e4b097 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -266,7 +266,8 @@ class LangFuseLogger: trace_name = metadata.get("trace_name", None) trace_id = metadata.get("trace_id", None) - if trace_name is None and trace_id is None: + existing_trace_id = metadata.get("existing_trace_id", None) + if trace_name is None and existing_trace_id is None: # just log `litellm-{call_type}` as the trace name ## DO NOT SET TRACE_NAME if trace-id set. this can lead to overwriting of past traces. trace_name = f"litellm-{kwargs.get('call_type', 'completion')}" @@ -275,7 +276,7 @@ class LangFuseLogger: "name": trace_name, "input": input, "user_id": metadata.get("trace_user_id", user_id), - "id": trace_id, + "id": trace_id or existing_trace_id, "session_id": metadata.get("session_id", None), }