store attributes values in builtin types to avoid otel warnings (#649)

# What does this PR do?

Serialize objects to built in types to avoid otel warnings


## Test Plan

╰─❯ llama stack run
~/.llama/distributions/llamastack-together/together-run.yaml
This commit is contained in:
Dinesh Yeduguru 2024-12-17 17:10:43 -08:00 committed by GitHub
parent 0e2a99e223
commit 3700022d6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View file

@ -6,10 +6,8 @@
import asyncio
import inspect
from datetime import datetime
from functools import wraps
from typing import Any, AsyncGenerator, Callable, Type, TypeVar
from uuid import UUID
from pydantic import BaseModel
@ -19,17 +17,17 @@ T = TypeVar("T")
def serialize_value(value: Any) -> Any:
"""Serialize a single value into JSON-compatible format."""
if value is None:
return None
return ""
elif isinstance(value, (str, int, float, bool)):
return value
elif hasattr(value, "_name_"):
return value._name_
elif isinstance(value, BaseModel):
return value.model_dump()
return value.model_dump_json()
elif isinstance(value, (list, tuple, set)):
return [serialize_value(item) for item in value]
elif isinstance(value, dict):
return {str(k): serialize_value(v) for k, v in value.items()}
elif isinstance(value, (datetime, UUID)):
return str(value)
else:
return str(value)