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
use safe dumps for arize ai
Ishaan Jaff48663a0920c8
diff --git a/litellm/integrations/arize/_utils.py b/litellm/integrations/arize/_utils.pyindex 4697245f574..68230855d0e 100644--- a/litellm/integrations/arize/_utils.py+++ b/litellm/integrations/arize/_utils.py@@ -2,10 +2,12 @@ import jsonfrom typing import TYPE_CHECKING, Any, Optionalfrom litellm._logging import verbose_logger+from litellm.litellm_core_utils.safe_json_dumps import safe_dumpsfrom litellm.types.utils import StandardLoggingPayloadif TYPE_CHECKING:from opentelemetry.trace import Span as _Span+Span = _Spanelse:Span = Any@@ -22,13 +24,15 @@ def set_attributes(span: Span, kwargs, response_obj):standard_logging_payload: Optional[StandardLoggingPayload] = kwargs.get("standard_logging_object")-+######################################################### LLM CALL METADATA ###########################################################-- if standard_logging_payload and (metadata := standard_logging_payload["metadata"]):- span.set_attribute(SpanAttributes.METADATA, json.dumps(metadata))++ if standard_logging_payload and (+ metadata := standard_logging_payload["metadata"]+ ):+ span.set_attribute(SpanAttributes.METADATA, safe_dumps(metadata))####################################################### LLM Request Attributes ###########@@ -65,10 +69,12 @@ def set_attributes(span: Span, kwargs, response_obj):msg.get("content", ""),)- if standard_logging_payload and (model_params := standard_logging_payload["model_parameters"]):+ if standard_logging_payload and (+ model_params := standard_logging_payload["model_parameters"]+ ):# The Generative AI Provider: Azure, OpenAI, etc.span.set_attribute(- SpanAttributes.LLM_INVOCATION_PARAMETERS, json.dumps(model_params)+ SpanAttributes.LLM_INVOCATION_PARAMETERS, safe_dumps(model_params))if model_params.get("user"):@@ -80,7 +86,7 @@ def set_attributes(span: Span, kwargs, response_obj):########## LLM Response Attributes ########### https://docs.arize.com/arize/large-language-models/tracing/semantic-conventions#############################################- if hasattr(response_obj, 'get'):+ if hasattr(response_obj, "get"):for choice in response_obj.get("choices", []):response_message = choice.get("message", {})span.set_attribute(