@@ -991,27 +991,27 @@ def _get_input_attributes(template, send_pii, args, kwargs):
991991 """
992992 attributes = {} # type: dict[str, Any]
993993
994- mapping = {
995- "model" : (SPANDATA .GEN_AI_REQUEST_MODEL , str ),
996- "model_name" : (SPANDATA .GEN_AI_REQUEST_MODEL , str ),
997- "agent" : (SPANDATA .GEN_AI_AGENT_NAME , str ),
998- "agent_name" : (SPANDATA .GEN_AI_AGENT_NAME , str ),
999- "max_tokens" : (SPANDATA .GEN_AI_REQUEST_MAX_TOKENS , int ),
1000- "frequency_penalty" : (SPANDATA .GEN_AI_REQUEST_FREQUENCY_PENALTY , float ),
1001- "presence_penalty" : (SPANDATA .GEN_AI_REQUEST_PRESENCE_PENALTY , float ),
1002- "temperature" : (SPANDATA .GEN_AI_REQUEST_TEMPERATURE , float ),
1003- "top_p" : (SPANDATA .GEN_AI_REQUEST_TOP_P , float ),
1004- "top_k" : (SPANDATA .GEN_AI_REQUEST_TOP_K , int ),
1005- }
994+ if template in [SPANTEMPLATE .AI_AGENT , SPANTEMPLATE .AI_TOOL , SPANTEMPLATE .AI_CHAT ]:
995+ mapping = {
996+ "model" : (SPANDATA .GEN_AI_REQUEST_MODEL , str ),
997+ "model_name" : (SPANDATA .GEN_AI_REQUEST_MODEL , str ),
998+ "agent" : (SPANDATA .GEN_AI_AGENT_NAME , str ),
999+ "agent_name" : (SPANDATA .GEN_AI_AGENT_NAME , str ),
1000+ "max_tokens" : (SPANDATA .GEN_AI_REQUEST_MAX_TOKENS , int ),
1001+ "frequency_penalty" : (SPANDATA .GEN_AI_REQUEST_FREQUENCY_PENALTY , float ),
1002+ "presence_penalty" : (SPANDATA .GEN_AI_REQUEST_PRESENCE_PENALTY , float ),
1003+ "temperature" : (SPANDATA .GEN_AI_REQUEST_TEMPERATURE , float ),
1004+ "top_p" : (SPANDATA .GEN_AI_REQUEST_TOP_P , float ),
1005+ "top_k" : (SPANDATA .GEN_AI_REQUEST_TOP_K , int ),
1006+ }
10061007
1007- def _set_from_key (key , value ):
1008- # type: (str, Any) -> None
1009- if key in mapping :
1010- (attribute , data_type ) = mapping [key ]
1011- if value is not None and isinstance (value , data_type ):
1012- attributes [attribute ] = value
1008+ def _set_from_key (key , value ):
1009+ # type: (str, Any) -> None
1010+ if key in mapping :
1011+ (attribute , data_type ) = mapping [key ]
1012+ if value is not None and isinstance (value , data_type ):
1013+ attributes [attribute ] = value
10131014
1014- if template in [SPANTEMPLATE .AI_AGENT , SPANTEMPLATE .AI_TOOL , SPANTEMPLATE .AI_CHAT ]:
10151015 for key , value in list (kwargs .items ()):
10161016 if key == "prompt" and isinstance (value , str ):
10171017 attributes .setdefault (SPANDATA .GEN_AI_REQUEST_MESSAGES , []).append (
@@ -1027,16 +1027,17 @@ def _set_from_key(key, value):
10271027
10281028 _set_from_key (key , value )
10291029
1030- if SPANDATA .GEN_AI_REQUEST_MESSAGES in attributes :
1031- attributes [SPANDATA .GEN_AI_REQUEST_MESSAGES ] = safe_repr (
1032- attributes [SPANDATA .GEN_AI_REQUEST_MESSAGES ]
1033- )
1034-
10351030 if template == SPANTEMPLATE .AI_TOOL and send_pii :
10361031 attributes [SPANDATA .GEN_AI_TOOL_INPUT ] = safe_repr (
10371032 {"args" : args , "kwargs" : kwargs }
10381033 )
10391034
1035+ # Coerce to string
1036+ if SPANDATA .GEN_AI_REQUEST_MESSAGES in attributes :
1037+ attributes [SPANDATA .GEN_AI_REQUEST_MESSAGES ] = safe_repr (
1038+ attributes [SPANDATA .GEN_AI_REQUEST_MESSAGES ]
1039+ )
1040+
10401041 return attributes
10411042
10421043
0 commit comments