@@ -467,7 +467,17 @@ def _maybe_log_completion_details(
467467 input_messages = to_input_messages (contents = transformers .t_contents (request ))
468468 output_messages = to_output_messages (candidates = response .candidates or [])
469469
470- span = None
470+ span = trace .get_current_span ()
471+ event = Event (
472+ name = "gen_ai.client.inference.operation.details" , attributes = attributes
473+ )
474+ self .completion_hook .on_completion (
475+ inputs = input_messages ,
476+ outputs = output_messages ,
477+ system_instruction = system_instructions ,
478+ span = span ,
479+ log_record = event ,
480+ )
471481 if self ._content_recording_enabled in [
472482 ContentCapturingMode .SPAN_ONLY ,
473483 ContentCapturingMode .SPAN_AND_EVENT ,
@@ -478,7 +488,6 @@ def _maybe_log_completion_details(
478488 system_instructions ,
479489 as_str = True ,
480490 )
481- span = trace .get_current_span ()
482491 span .set_attributes (completion_details_attributes )
483492 if self ._content_recording_enabled in [
484493 ContentCapturingMode .EVENT_ONLY ,
@@ -489,18 +498,11 @@ def _maybe_log_completion_details(
489498 output_messages ,
490499 system_instructions ,
491500 )
492- attributes .update (completion_details_attributes )
493- event = Event (
494- name = "gen_ai.client.inference.operation.details" , attributes = attributes
495- )
496- self .completion_hook .on_completion (
497- inputs = input_messages ,
498- outputs = output_messages ,
499- system_instruction = system_instructions ,
500- span = span ,
501- log_record = event ,
502- )
503- self ._otel_wrapper .log_completion_details (event = event )
501+ event .attributes = {
502+ ** (event .attributes or {}),
503+ ** completion_details_attributes ,
504+ }
505+ self ._otel_wrapper .log_completion_details (event = event )
504506
505507 def _maybe_log_system_instruction (
506508 self , config : Optional [GenerateContentConfigOrDict ] = None
0 commit comments