@@ -436,7 +436,6 @@ def _handle_completion_success(transaction, linking_metadata, completion_id, kwa
436436 trace_id = linking_metadata .get ("trace.id" )
437437 request_message_list = kwargs .get ("messages" ) or []
438438 stream = kwargs .get ("stream" , False )
439-
440439 # Only if streaming and streaming monitoring is enabled and the response is not empty
441440 # do we not exit the function trace.
442441 if not stream or not settings .ai_monitoring .streaming .enabled or not return_val :
@@ -476,16 +475,12 @@ def _handle_completion_success(transaction, linking_metadata, completion_id, kwa
476475 # openai._legacy_response.LegacyAPIResponse
477476 response = json .loads (response .http_response .text .strip ())
478477
479- _record_completion_success (
480- transaction , linking_metadata , completion_id , kwargs , ft , response_headers , response
481- )
478+ _record_completion_success (transaction , linking_metadata , completion_id , kwargs , ft , response_headers , response )
482479 except Exception :
483480 _logger .warning (RECORD_EVENTS_FAILURE_LOG_MESSAGE % traceback .format_exception (* sys .exc_info ()))
484481
485482
486- def _record_completion_success (
487- transaction , linking_metadata , completion_id , kwargs , ft , response_headers , response
488- ):
483+ def _record_completion_success (transaction , linking_metadata , completion_id , kwargs , ft , response_headers , response ):
489484 span_id = linking_metadata .get ("span.id" )
490485 trace_id = linking_metadata .get ("trace.id" )
491486 try :
@@ -647,7 +642,6 @@ def _record_completion_error(transaction, linking_metadata, completion_id, kwarg
647642 }
648643 llm_metadata = _get_llm_attributes (transaction )
649644 error_chat_completion_dict .update (llm_metadata )
650-
651645 transaction .record_custom_event ("LlmChatCompletionSummary" , error_chat_completion_dict )
652646
653647 output_message_list = []
@@ -786,20 +780,15 @@ def _record_events_on_stop_iteration(self, transaction):
786780 self ._nr_ft .__exit__ (None , None , None )
787781 try :
788782 openai_attrs = getattr (self , "_nr_openai_attrs" , {})
783+
789784 # If there are no openai attrs exit early as there's no data to record.
790785 if not openai_attrs :
791786 return
792787
793788 completion_id = str (uuid .uuid4 ())
794789 response_headers = openai_attrs .get ("response_headers" ) or {}
795790 _record_completion_success (
796- transaction ,
797- linking_metadata ,
798- completion_id ,
799- openai_attrs ,
800- self ._nr_ft ,
801- response_headers ,
802- None
791+ transaction , linking_metadata , completion_id , openai_attrs , self ._nr_ft , response_headers , None
803792 )
804793 except Exception :
805794 _logger .warning (RECORD_EVENTS_FAILURE_LOG_MESSAGE % traceback .format_exception (* sys .exc_info ()))
@@ -824,10 +813,7 @@ def _handle_streaming_completion_error(self, transaction, exc):
824813 return
825814 linking_metadata = get_trace_linking_metadata ()
826815 completion_id = str (uuid .uuid4 ())
827-
828- _record_completion_error (
829- transaction , linking_metadata , completion_id , openai_attrs , self ._nr_ft , exc
830- )
816+ _record_completion_error (transaction , linking_metadata , completion_id , openai_attrs , self ._nr_ft , exc )
831817
832818
833819class AsyncGeneratorProxy (ObjectProxy ):
0 commit comments