@@ -268,7 +268,7 @@ def _create_event_attributes(
268268 attrs [GEN_AI_MESSAGE_ID ] = message_id
269269
270270 if message_status :
271- attrs [GEN_AI_MESSAGE_STATUS ] = message_status
271+ attrs [GEN_AI_MESSAGE_STATUS ] = self . _status_to_string ( message_status )
272272
273273 if usage :
274274 attrs [GEN_AI_USAGE_INPUT_TOKENS ] = usage .prompt_tokens
@@ -287,7 +287,7 @@ def add_thread_message_event(
287287 content_details = {"value" : self ._get_field (typed_content , "value" )}
288288 annotations = self ._get_field (typed_content , "annotations" )
289289 if annotations :
290- content_details ["annotations" ] = annotations
290+ content_details ["annotations" ] = [ a . as_dict () for a in annotations ]
291291 content_body [content .type ] = content_details
292292
293293 self ._add_message_event (
@@ -386,6 +386,9 @@ def _get_role(self, role: Optional[Union[str, MessageRole]]) -> str:
386386
387387 return role
388388
389+ def _status_to_string (self , status : Any ) -> str :
390+ return status .value if hasattr (status , "value" ) else status
391+
389392 def _add_tool_assistant_message_event (self , span , step : RunStep ) -> None :
390393 # do we want a new event for it ?
391394 tool_calls = [
@@ -418,7 +421,7 @@ def _add_tool_assistant_message_event(self, span, step: RunStep) -> None:
418421
419422 def set_end_run (self , span : "AbstractSpan" , run : Optional [ThreadRun ]) -> None :
420423 if run and span and span .span_instance .is_recording :
421- span .add_attribute (GEN_AI_THREAD_RUN_STATUS , run .status )
424+ span .add_attribute (GEN_AI_THREAD_RUN_STATUS , self . _status_to_string ( run .status ) )
422425 span .add_attribute (GEN_AI_RESPONSE_MODEL , run .model )
423426 if run and run .usage :
424427 span .add_attribute (GEN_AI_USAGE_INPUT_TOKENS , run .usage .prompt_tokens )
@@ -897,7 +900,7 @@ async def trace_create_run_async(self, operation_name, function, *args, **kwargs
897900 try :
898901 result = await function (* args , ** kwargs )
899902 if span .span_instance .is_recording :
900- span .add_attribute (GEN_AI_THREAD_RUN_STATUS , result .status )
903+ span .add_attribute (GEN_AI_THREAD_RUN_STATUS , self . _status_to_string ( result .status ) )
901904 span .add_attribute (GEN_AI_RESPONSE_MODEL , result .model )
902905 if result .usage :
903906 span .add_attribute (GEN_AI_USAGE_INPUT_TOKENS , result .usage .prompt_tokens )
@@ -1700,7 +1703,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
17001703 self .instrumentor .set_end_run (self .span , self .last_run )
17011704
17021705 if self .last_run and self .last_run .last_error :
1703- self .span .set_status (
1706+ self .span .span_instance . set_status (
17041707 StatusCode .ERROR , # pyright: ignore [reportPossiblyUnboundVariable]
17051708 self .last_run .last_error .message ,
17061709 )
0 commit comments