mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 02:53:30 +00:00
feat: make telemetry attributes be dict[str,PrimitiveType] (#1055)
# What does this PR do? Make attributes in telemetry be only primitive types and avoid arbitrary nesting. ## Test Plan ``` LLAMA_STACK_DISABLE_VERSION_CHECK=true llama stack run ~/.llama/distributions/fireworks/fireworks-run.yaml LLAMA_STACK_BASE_URL=http://localhost:8321 pytest -v tests/client-sdk/agents/test_agents.py -k "test_builtin_tool_web_search" # Verified that attributes still show up correclty in jaeger ```
This commit is contained in:
parent
ab7f802698
commit
d8a20e034b
4 changed files with 29 additions and 45 deletions
|
@ -9,12 +9,13 @@ import inspect
|
|||
from functools import wraps
|
||||
from typing import Any, AsyncGenerator, Callable, Type, TypeVar
|
||||
|
||||
from llama_models.llama3.api.datatypes import Primitive
|
||||
from pydantic import BaseModel
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def serialize_value(value: Any) -> Any:
|
||||
def serialize_value(value: Any) -> Primitive:
|
||||
"""Serialize a single value into JSON-compatible format."""
|
||||
if value is None:
|
||||
return ""
|
||||
|
@ -24,10 +25,6 @@ def serialize_value(value: Any) -> Any:
|
|||
return value._name_
|
||||
elif isinstance(value, BaseModel):
|
||||
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()}
|
||||
else:
|
||||
return str(value)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue