@@ -215,6 +215,21 @@ def _record_embedding_metrics(
215215 # metric support is added.
216216 return
217217
218+ def _call_completion_hook (
219+ self ,
220+ invocation : LLMInvocation ,
221+ span : Span ,
222+ log_record : object ,
223+ ) -> None :
224+ if self ._completion_hook is not None :
225+ self ._completion_hook .on_completion (
226+ inputs = invocation .input_messages ,
227+ outputs = invocation .output_messages ,
228+ system_instruction = invocation .system_instruction ,
229+ span = span ,
230+ log_record = log_record ,
231+ )
232+
218233 def _start (self , invocation : _T ) -> _T :
219234 """Start a GenAI invocation and create a pending span entry."""
220235 if isinstance (invocation , LLMInvocation ):
@@ -254,14 +269,7 @@ def _stop(self, invocation: _T) -> _T:
254269 _apply_llm_finish_attributes (span , invocation )
255270 self ._record_llm_metrics (invocation , span )
256271 log_record = _maybe_build_llm_event_record (span , invocation )
257- if self ._completion_hook is not None :
258- self ._completion_hook .on_completion (
259- inputs = invocation .input_messages ,
260- outputs = invocation .output_messages ,
261- system_instruction = invocation .system_instruction ,
262- span = span ,
263- log_record = log_record ,
264- )
272+ self ._call_completion_hook (invocation , span , log_record )
265273 if log_record is not None :
266274 self ._logger .emit (log_record )
267275 elif isinstance (invocation , EmbeddingInvocation ):
0 commit comments