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
test_arize_callback
Ishaan Jaff19a7bfa6b5d1
diff --git a/tests/local_testing/test_arize_ai.py b/tests/local_testing/test_arize_ai.pyindex 9e668140d06..e578bb41880 100644--- a/tests/local_testing/test_arize_ai.py+++ b/tests/local_testing/test_arize_ai.py@@ -1,7 +1,10 @@import asyncioimport jsonimport logging-+import os+import time+from unittest.mock import patch, Mock+import opentelemetry.exporter.otlp.proto.grpc.trace_exporterfrom litellm import Choicesimport pytestfrom dotenv import load_dotenv@@ -60,3 +63,49 @@ def test_get_arize_config_with_endpoints(mock_env_vars, monkeypatch):config = ArizeLogger.get_arize_config()assert config.endpoint == "grpc://test.endpoint"assert config.protocol == "otlp_grpc"+++def test_arize_callback():+ litellm.callbacks = ["arize"]+ os.environ["ARIZE_SPACE_KEY"] = "test_space_key"+ os.environ["ARIZE_API_KEY"] = "test_api_key"+ os.environ["ARIZE_ENDPOINT"] = "https://otlp.arize.com/v1"++ # Set the batch span processor to quickly flush after a span has been added+ # This is to ensure that the span is exported before the test ends+ os.environ["OTEL_BSP_MAX_QUEUE_SIZE"] = "1"+ os.environ["OTEL_BSP_MAX_EXPORT_BATCH_SIZE"] = "1"+ os.environ["OTEL_BSP_SCHEDULE_DELAY_MILLIS"] = "1"+ os.environ["OTEL_BSP_EXPORT_TIMEOUT_MILLIS"] = "5"++ try:+ with patch.object(+ opentelemetry.exporter.otlp.proto.grpc.trace_exporter.OTLPSpanExporter,+ "export",+ new=Mock(),+ ) as patched_export:+ litellm.completion(+ model="openai/test-model",+ messages=[{"role": "user", "content": "arize test content"}],+ stream=False,+ mock_response="hello there!",+ )++ time.sleep(1) # Wait for the batch span processor to flush+ assert patched_export.called+ finally:+ # Clean up environment variables+ for key in [+ "ARIZE_SPACE_KEY",+ "ARIZE_API_KEY",+ "ARIZE_ENDPOINT",+ "OTEL_BSP_MAX_QUEUE_SIZE",+ "OTEL_BSP_MAX_EXPORT_BATCH_SIZE",+ "OTEL_BSP_SCHEDULE_DELAY_MILLIS",+ "OTEL_BSP_EXPORT_TIMEOUT_MILLIS",+ ]:+ if key in os.environ:+ del os.environ[key]++ # Reset callbacks+ litellm.callbacks = []diff --git a/tests/logging_callback_tests/test_arize_logging.py b/tests/logging_callback_tests/test_arize_logging.pyindex 426504af2aa..5e8428c8137 100644--- a/tests/logging_callback_tests/test_arize_logging.py+++ b/tests/logging_callback_tests/test_arize_logging.py@@ -15,52 +15,6 @@ import litellmfrom litellm.types.utils import Choices-def test_arize_callback():- litellm.callbacks = ["arize"]- os.environ["ARIZE_SPACE_KEY"] = "test_space_key"- os.environ["ARIZE_API_KEY"] = "test_api_key"- os.environ["ARIZE_ENDPOINT"] = "https://otlp.arize.com/v1"-- # Set the batch span processor to quickly flush after a span has been added- # This is to ensure that the span is exported before the test ends- os.environ["OTEL_BSP_MAX_QUEUE_SIZE"] = "1"- os.environ["OTEL_BSP_MAX_EXPORT_BATCH_SIZE"] = "1"- os.environ["OTEL_BSP_SCHEDULE_DELAY_MILLIS"] = "1"- os.environ["OTEL_BSP_EXPORT_TIMEOUT_MILLIS"] = "5"-- try:- with patch.object(- opentelemetry.exporter.otlp.proto.grpc.trace_exporter.OTLPSpanExporter,- "export",- new=Mock(),- ) as patched_export:- completion(- model="openai/test-model",- messages=[{"role": "user", "content": "arize test content"}],- stream=False,- mock_response="hello there!",- )-- time.sleep(1) # Wait for the batch span processor to flush- assert patched_export.called- finally:- # Clean up environment variables- for key in [- "ARIZE_SPACE_KEY",- "ARIZE_API_KEY",- "ARIZE_ENDPOINT",- "OTEL_BSP_MAX_QUEUE_SIZE",- "OTEL_BSP_MAX_EXPORT_BATCH_SIZE",- "OTEL_BSP_SCHEDULE_DELAY_MILLIS",- "OTEL_BSP_EXPORT_TIMEOUT_MILLIS",- ]:- if key in os.environ:- del os.environ[key]-- # Reset callbacks- litellm.callbacks = []--def test_arize_set_attributes():"""Test setting attributes for Arize