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: add default value to pass the opik test
mrFranklin02a41d76be96
diff --git a/litellm/integrations/opik/opik.py b/litellm/integrations/opik/opik.pyindex 94fbcfe2016..5d98f220f38 100644--- a/litellm/integrations/opik/opik.py+++ b/litellm/integrations/opik/opik.py@@ -202,7 +202,10 @@ class OpikLogger(CustomBatchLogger):return []# Update litellm_opik_metadata with opik metadata from requester- litellm_opik_metadata.update(standard_logging_object.get("metadata", {}).get("requester_metadata", {}).get("opik", {}))+ standard_logging_metadata = standard_logging_object.get("metadata", {}) or {}+ requester_metadata = standard_logging_metadata.get("requester_metadata", {}) or {}+ requester_opik_metadata = requester_metadata.get("opik", {}) or {}+ litellm_opik_metadata.update(requester_opik_metadata)verbose_logger.debug(f"litellm_opik_metadata - {json.dumps(litellm_opik_metadata, default=str)}"@@ -230,7 +233,8 @@ class OpikLogger(CustomBatchLogger):thread_id = litellm_opik_metadata.get("thread_id", None)# Override with any opik_ headers from proxy request- proxy_headers = (_litellm_params.get("proxy_server_request", {}).get("headers", {}) or {})+ proxy_server_request = _litellm_params.get("proxy_server_request", {}) or {}+ proxy_headers = proxy_server_request.get("headers", {}) or {}for key, value in proxy_headers.items():if key.startswith("opik_"):param_key = key.replace("opik_", "", 1)@@ -249,8 +253,7 @@ class OpikLogger(CustomBatchLogger):opik_tags.extend(parsed_tags)except (json.JSONDecodeError, TypeError):pass--+# Create input and output datainput_data = standard_logging_object.get("messages", {})output_data = standard_logging_object.get("response", {})@@ -273,7 +276,7 @@ class OpikLogger(CustomBatchLogger):del metadata["current_span_data"]metadata["created_from"] = "litellm"- metadata.update(standard_logging_object.get("metadata", {}))+ metadata.update(standard_logging_metadata)if "call_type" in standard_logging_object:metadata["type"] = standard_logging_object["call_type"]if "status" in standard_logging_object:diff --git a/tests/local_testing/test_opik.py b/tests/local_testing/test_opik.pyindex 62c17fbb2d5..d43b7558f54 100644--- a/tests/local_testing/test_opik.py+++ b/tests/local_testing/test_opik.py@@ -122,7 +122,7 @@ def test_sync_opik_logging_http_request():)# Need to wait for a short amount of time as the log_success callback is called in a different thread- time.sleep(1)+ time.sleep(3)# Check that 5 spans and 5 traces were sentassert mock_post.call_count == 10, f"Expected 10 HTTP requests, but got {mock_post.call_count}"