@@ -366,7 +366,9 @@ def process_request(
366366 self ,
367367 contents : Union [ContentListUnion , ContentListUnionDict ],
368368 config : Optional [GenerateContentConfigOrDict ],
369+ span : Span ,
369370 ):
371+ span .set_attribute (gen_ai_attributes .GEN_AI_SYSTEM , self ._genai_system )
370372 self ._maybe_log_system_instruction (config = config )
371373 self ._maybe_log_user_prompt (contents )
372374
@@ -728,10 +730,7 @@ def instrumented_generate_content(
728730 ) as span :
729731 span .set_attributes (request_attributes )
730732 if helper .sem_conv_opt_in_mode == _StabilityMode .DEFAULT :
731- helper .process_request (contents , config )
732- span .set_attribute (
733- gen_ai_attributes .GEN_AI_SYSTEM , helper ._genai_system
734- )
733+ helper .process_request (contents , config , span )
735734 try :
736735 response = wrapped_func (
737736 self ,
@@ -806,10 +805,7 @@ def instrumented_generate_content_stream(
806805 ) as span :
807806 span .set_attributes (request_attributes )
808807 if helper .sem_conv_opt_in_mode == _StabilityMode .DEFAULT :
809- helper .process_request (contents , config )
810- span .set_attribute (
811- gen_ai_attributes .GEN_AI_SYSTEM , helper ._genai_system
812- )
808+ helper .process_request (contents , config , span )
813809 try :
814810 for response in wrapped_func (
815811 self ,
@@ -884,10 +880,7 @@ async def instrumented_generate_content(
884880 ) as span :
885881 span .set_attributes (request_attributes )
886882 if helper .sem_conv_opt_in_mode == _StabilityMode .DEFAULT :
887- helper .process_request (contents , config )
888- span .set_attribute (
889- gen_ai_attributes .GEN_AI_SYSTEM , helper ._genai_system
890- )
883+ helper .process_request (contents , config , span )
891884 try :
892885 response = await wrapped_func (
893886 self ,
@@ -963,10 +956,7 @@ async def instrumented_generate_content_stream(
963956 ) as span :
964957 span .set_attributes (request_attributes )
965958 if not is_experimental_mode :
966- helper .process_request (contents , config )
967- span .set_attribute (
968- gen_ai_attributes .GEN_AI_SYSTEM , helper ._genai_system
969- )
959+ helper .process_request (contents , config , span )
970960 try :
971961 response_async_generator = await wrapped_func (
972962 self ,
0 commit comments