@@ -700,7 +700,7 @@ def _process_event(self, event: Any) -> None:
700700 response = event .response
701701 if hasattr (response , "usage" ):
702702 self ._usage = response .usage
703-
703+
704704 # Extract output items from the completed response
705705 if hasattr (response , "output" ):
706706 for output_item in response .output :
@@ -723,13 +723,21 @@ def _process_event(self, event: Any) -> None:
723723 # Extract text content from message items
724724 if isinstance (output_item .content , list ):
725725 for content in output_item .content :
726- if hasattr (content , "type" ) and content .type == "text" and hasattr (content , "text" ):
726+ if (
727+ hasattr (content , "type" )
728+ and content .type == "text"
729+ and hasattr (content , "text" )
730+ ):
727731 self ._content_chunks .append (str (content .text ))
728732 else :
729733 self ._content_chunks .append (str (output_item .content ))
730734
731735 # Only add significant events, not every delta
732- if hasattr (event , "type" ) and event .type in ["response.created" , "response.completed" , "response.output_item.added" ]:
736+ if hasattr (event , "type" ) and event .type in [
737+ "response.created" ,
738+ "response.completed" ,
739+ "response.output_item.added" ,
740+ ]:
733741 self ._span .add_event (
734742 "responses_api_event" ,
735743 {"event_type" : event .type , "event_number" : self ._event_count },
@@ -743,7 +751,7 @@ def _finalize_stream(self) -> None:
743751 text_content = "" .join (self ._content_chunks )
744752 function_content = self ._current_function_args or "" .join (self ._function_call_chunks )
745753 reasoning_content = "" .join (self ._reasoning_chunks )
746-
754+
747755 # Combine all content types for the completion
748756 full_content = ""
749757 if reasoning_content :
@@ -758,10 +766,14 @@ def _finalize_stream(self) -> None:
758766 full_content += f"\n Response: { text_content } "
759767 else :
760768 full_content = text_content
761-
769+
762770 if full_content :
763771 self ._span .set_attribute (MessageAttributes .COMPLETION_CONTENT .format (i = 0 ), full_content )
764- logger .debug (f"[RESPONSES API] Setting completion content: { full_content [:100 ]} ..." if len (full_content ) > 100 else f"[RESPONSES API] Setting completion content: { full_content } " )
772+ logger .debug (
773+ f"[RESPONSES API] Setting completion content: { full_content [:100 ]} ..."
774+ if len (full_content ) > 100
775+ else f"[RESPONSES API] Setting completion content: { full_content } "
776+ )
765777
766778 # Set timing
767779 if self ._first_token_time :
@@ -809,7 +821,9 @@ def _finalize_stream(self) -> None:
809821 self ._span .set_status (Status (StatusCode .OK ))
810822 self ._span .end ()
811823 context_api .detach (self ._token )
812- logger .debug (f"[RESPONSES API] Finalized streaming span after { self ._event_count } events. Content length: { len (full_content )} " )
824+ logger .debug (
825+ f"[RESPONSES API] Finalized streaming span after { self ._event_count } events. Content length: { len (full_content )} "
826+ )
813827
814828
815829@_with_tracer_wrapper
@@ -836,7 +850,7 @@ def responses_stream_wrapper(tracer, wrapped, instance, args, kwargs):
836850 try :
837851 # Extract and set request attributes
838852 from agentops .instrumentation .providers .openai .wrappers .responses import handle_responses_attributes
839-
853+
840854 request_attributes = handle_responses_attributes (kwargs = kwargs )
841855 for key , value in request_attributes .items ():
842856 span .set_attribute (key , value )
@@ -854,7 +868,7 @@ def responses_stream_wrapper(tracer, wrapped, instance, args, kwargs):
854868 for key , value in response_attributes .items ():
855869 if key not in request_attributes : # Avoid overwriting request attributes
856870 span .set_attribute (key , value )
857-
871+
858872 span .set_status (Status (StatusCode .OK ))
859873 span .end ()
860874 context_api .detach (token )
@@ -893,7 +907,7 @@ async def async_responses_stream_wrapper(tracer, wrapped, instance, args, kwargs
893907 try :
894908 # Extract and set request attributes
895909 from agentops .instrumentation .providers .openai .wrappers .responses import handle_responses_attributes
896-
910+
897911 request_attributes = handle_responses_attributes (kwargs = kwargs )
898912 for key , value in request_attributes .items ():
899913 span .set_attribute (key , value )
@@ -912,7 +926,7 @@ async def async_responses_stream_wrapper(tracer, wrapped, instance, args, kwargs
912926 for key , value in response_attributes .items ():
913927 if key not in request_attributes : # Avoid overwriting request attributes
914928 span .set_attribute (key , value )
915-
929+
916930 span .set_status (Status (StatusCode .OK ))
917931 span .end ()
918932 context_api .detach (token )
0 commit comments