@@ -268,7 +268,7 @@ def _create_event_attributes(
268
268
attrs [GEN_AI_MESSAGE_ID ] = message_id
269
269
270
270
if message_status :
271
- attrs [GEN_AI_MESSAGE_STATUS ] = message_status
271
+ attrs [GEN_AI_MESSAGE_STATUS ] = self . _status_to_string ( message_status )
272
272
273
273
if usage :
274
274
attrs [GEN_AI_USAGE_INPUT_TOKENS ] = usage .prompt_tokens
@@ -287,7 +287,7 @@ def add_thread_message_event(
287
287
content_details = {"value" : self ._get_field (typed_content , "value" )}
288
288
annotations = self ._get_field (typed_content , "annotations" )
289
289
if annotations :
290
- content_details ["annotations" ] = annotations
290
+ content_details ["annotations" ] = [ a . as_dict () for a in annotations ]
291
291
content_body [content .type ] = content_details
292
292
293
293
self ._add_message_event (
@@ -386,6 +386,9 @@ def _get_role(self, role: Optional[Union[str, MessageRole]]) -> str:
386
386
387
387
return role
388
388
389
+ def _status_to_string (self , status : Any ) -> str :
390
+ return status .value if hasattr (status , "value" ) else status
391
+
389
392
def _add_tool_assistant_message_event (self , span , step : RunStep ) -> None :
390
393
# do we want a new event for it ?
391
394
tool_calls = [
@@ -418,7 +421,7 @@ def _add_tool_assistant_message_event(self, span, step: RunStep) -> None:
418
421
419
422
def set_end_run (self , span : "AbstractSpan" , run : Optional [ThreadRun ]) -> None :
420
423
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 ) )
422
425
span .add_attribute (GEN_AI_RESPONSE_MODEL , run .model )
423
426
if run and run .usage :
424
427
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
897
900
try :
898
901
result = await function (* args , ** kwargs )
899
902
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 ) )
901
904
span .add_attribute (GEN_AI_RESPONSE_MODEL , result .model )
902
905
if result .usage :
903
906
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):
1700
1703
self .instrumentor .set_end_run (self .span , self .last_run )
1701
1704
1702
1705
if self .last_run and self .last_run .last_error :
1703
- self .span .set_status (
1706
+ self .span .span_instance . set_status (
1704
1707
StatusCode .ERROR , # pyright: ignore [reportPossiblyUnboundVariable]
1705
1708
self .last_run .last_error .message ,
1706
1709
)
0 commit comments