@@ -467,7 +467,17 @@ def _maybe_log_completion_details(
467
467
input_messages = to_input_messages (contents = transformers .t_contents (request ))
468
468
output_messages = to_output_messages (candidates = response .candidates or [])
469
469
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
+ )
471
481
if self ._content_recording_enabled in [
472
482
ContentCapturingMode .SPAN_ONLY ,
473
483
ContentCapturingMode .SPAN_AND_EVENT ,
@@ -478,7 +488,6 @@ def _maybe_log_completion_details(
478
488
system_instructions ,
479
489
as_str = True ,
480
490
)
481
- span = trace .get_current_span ()
482
491
span .set_attributes (completion_details_attributes )
483
492
if self ._content_recording_enabled in [
484
493
ContentCapturingMode .EVENT_ONLY ,
@@ -489,18 +498,11 @@ def _maybe_log_completion_details(
489
498
output_messages ,
490
499
system_instructions ,
491
500
)
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 )
504
506
505
507
def _maybe_log_system_instruction (
506
508
self , config : Optional [GenerateContentConfigOrDict ] = None
0 commit comments