Skip to content

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]

[Fix] CI/CD - Fix failing proxy unit test and langfuse trace_id test (#17924)

Alexsander Hamir5b6b61356192
diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.py
index c8aaa13de51..10347bc7c67 100644
--- a/litellm/integrations/langfuse/langfuse.py
+++ b/litellm/integrations/langfuse/langfuse.py
@@ -539,12 +539,36 @@ class LangFuseLogger:
trace_id = clean_metadata.pop("trace_id", None)
# 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
+ # However, we skip standard_logging_object.trace_id if it's a UUID (from litellm_trace_id default),
+ # as we want to fall back to litellm_call_id instead for better traceability.
+ # Note: Users can still explicitly set a UUID trace_id via metadata["trace_id"] (highest priority)
if trace_id is None and standard_logging_object is not None:
- trace_id = cast(Optional[str], standard_logging_object.get("trace_id"))
+ standard_trace_id = cast(Optional[str], standard_logging_object.get("trace_id"))
+ # Only use standard_logging_object.trace_id if it's not a UUID
+ # UUIDs are 36 characters with hyphens in format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ # We check for this specific pattern to avoid rejecting valid trace_ids that happen to have hyphens
+ # This primarily filters out default litellm_trace_id UUIDs, while still allowing user-provided
+ # trace_ids via metadata["trace_id"] (which is checked first and not affected by this logic)
+ if standard_trace_id is not None:
+ # Check if it's a UUID: 36 chars, 4 hyphens, specific pattern
+ is_uuid = (
+ len(standard_trace_id) == 36
+ and standard_trace_id.count("-") == 4
+ and standard_trace_id[8] == "-"
+ and standard_trace_id[13] == "-"
+ and standard_trace_id[18] == "-"
+ and standard_trace_id[23] == "-"
+ )
+ if not is_uuid:
+ trace_id = standard_trace_id
# Fallback to litellm_call_id if no trace_id found
if trace_id is None:
trace_id = litellm_call_id
existing_trace_id = clean_metadata.pop("existing_trace_id", None)
+ # If existing_trace_id is provided, use it as the trace_id to return
+ # This allows continuing an existing trace while still returning the correct trace_id
+ if existing_trace_id is not None:
+ trace_id = existing_trace_id
update_trace_keys = cast(list, clean_metadata.pop("update_trace_keys", []))
debug = clean_metadata.pop("debug_langfuse", None)
mask_input = clean_metadata.pop("mask_input", False)
diff --git a/tests/proxy_unit_tests/test_user_api_key_auth.py b/tests/proxy_unit_tests/test_user_api_key_auth.py
index 1e3ec1e3019..ec61c7305bb 100644
--- a/tests/proxy_unit_tests/test_user_api_key_auth.py
+++ b/tests/proxy_unit_tests/test_user_api_key_auth.py
@@ -1036,7 +1036,7 @@ async def test_jwt_non_admin_team_route_access(monkeypatch):
# Create request
request = Request(
- scope={"type": "http", "headers": [("Authorization", "Bearer fake.jwt.token")]}
+ scope={"type": "http", "headers": [(b"authorization", b"Bearer fake.jwt.token")]}
)
request._url = URL(url="/team/new")