The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Fix Langfuse trace_id mapping for failed logs and prioritize session_id
Harshit28j7e9930cc3b4d
diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.pyindex 7bf97665fd2..70f1161792a 100644--- a/litellm/integrations/langfuse/langfuse.py+++ b/litellm/integrations/langfuse/langfuse.py@@ -604,9 +604,12 @@ class LangFuseLogger:session_id = clean_metadata.pop("session_id", None)trace_name = cast(Optional[str], clean_metadata.pop("trace_name", None))trace_id = clean_metadata.pop("trace_id", None)+ # If session_id is provided, use it as trace_id for consistent trace mapping+ if trace_id is None and session_id is not None:+ trace_id = session_id# Use standard_logging_object.trace_id if available (when trace_id from metadata is None)# This allows standard trace_id to be used when provided in standard_logging_object- if trace_id is None and standard_logging_object is not None:+ elif trace_id is None and standard_logging_object is not None:trace_id = cast(Optional[str], standard_logging_object.get("trace_id"))diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex e450b233c7e..d5419c98685 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -2953,7 +2953,7 @@ class Logging(LiteLLMLoggingBaseClass):user_id=kwargs.get("user", None),status_message=str(exception),level="ERROR",- kwargs=self.model_call_details,+ kwargs=kwargs,)if _response is not None and isinstance(_response, dict):_trace_id = _response.get("trace_id", None)