@@ -54,17 +54,20 @@ def configure_valid_response(self, response_text='The model_response', input_tok
5454 input_tokens = input_tokens ,
5555 output_tokens = output_tokens ))
5656
57+ def generate_content (self , * args , ** kwargs ):
58+ return self .client .models .generate_content (* args , ** kwargs )
59+
5760 def test_generates_span (self ):
5861 self .configure_valid_response (response_text = 'Yep, it works!' )
59- response = self .client . models . generate_content (
62+ response = self .generate_content (
6063 model = 'gemini-2.0-flash' ,
6164 contents = 'Does this work?' )
6265 self .assertEqual (response .text , 'Yep, it works!' )
6366 self .otel .assert_has_span_named ('google.genai.Models.generate_content' )
6467
6568 def test_generated_span_has_minimal_genai_attributes (self ):
6669 self .configure_valid_response (response_text = 'Yep, it works!' )
67- self .client . models . generate_content (
70+ self .generate_content (
6871 model = 'gemini-2.0-flash' ,
6972 contents = 'Does this work?' )
7073 self .otel .assert_has_span_named ('google.genai.Models.generate_content' )
@@ -74,7 +77,7 @@ def test_generated_span_has_minimal_genai_attributes(self):
7477
7578 def test_generated_span_counts_tokens (self ):
7679 self .configure_valid_response (input_tokens = 123 , output_tokens = 456 )
77- response = self .client . models . generate_content (
80+ response = self .generate_content (
7881 model = 'gemini-2.0-flash' ,
7982 contents = 'Some input' )
8083 self .otel .assert_has_span_named ('google.genai.Models.generate_content' )
@@ -88,7 +91,7 @@ def test_records_system_prompt_as_log(self):
8891 'system_instruction' : 'foo'
8992 }
9093 self .configure_valid_response ()
91- self .client . models . generate_content (
94+ self .generate_content (
9295 model = 'gemini-2.0-flash' ,
9396 contents = 'Some input' ,
9497 config = config )
@@ -103,7 +106,7 @@ def test_does_not_record_system_prompt_as_log_if_disabled_by_env(self):
103106 'system_instruction' : 'foo'
104107 }
105108 self .configure_valid_response ()
106- self .client . models . generate_content (
109+ self .generate_content (
107110 model = 'gemini-2.0-flash' ,
108111 contents = 'Some input' ,
109112 config = config )
@@ -112,15 +115,15 @@ def test_does_not_record_system_prompt_as_log_if_disabled_by_env(self):
112115 def test_does_not_record_system_prompt_as_log_if_no_system_prompt_present (self ):
113116 os .environ ['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT' ] = 'true'
114117 self .configure_valid_response ()
115- self .client . models . generate_content (
118+ self .generate_content (
116119 model = 'gemini-2.0-flash' ,
117120 contents = 'Some input' )
118121 self .otel .assert_does_not_have_event_named ('gen_ai.system.message' )
119122
120123 def test_records_user_prompt_as_log (self ):
121124 os .environ ['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT' ] = 'true'
122125 self .configure_valid_response ()
123- self .client . models . generate_content (
126+ self .generate_content (
124127 model = 'gemini-2.0-flash' ,
125128 contents = 'Some input' )
126129 self .otel .assert_has_event_named ('gen_ai.user.message' )
@@ -131,15 +134,15 @@ def test_records_user_prompt_as_log(self):
131134 def test_does_not_record_user_prompt_as_log_if_disabled_by_env (self ):
132135 os .environ ['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT' ] = 'false'
133136 self .configure_valid_response ()
134- self .client . models . generate_content (
137+ self .generate_content (
135138 model = 'gemini-2.0-flash' ,
136139 contents = 'Some input' )
137140 self .otel .assert_does_not_have_event_named ('gen_ai.user.message' )
138141
139142 def test_records_response_as_log (self ):
140143 os .environ ['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT' ] = 'true'
141144 self .configure_valid_response (response_text = 'Some response content' )
142- self .client . models . generate_content (
145+ self .generate_content (
143146 model = 'gemini-2.0-flash' ,
144147 contents = 'Some input' )
145148 self .otel .assert_has_event_named ('gen_ai.assistant.message' )
@@ -150,14 +153,14 @@ def test_records_response_as_log(self):
150153 def test_does_not_record_response_as_log_if_disabled_by_env (self ):
151154 os .environ ['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT' ] = 'false'
152155 self .configure_valid_response (response_text = 'Some response content' )
153- self .client . models . generate_content (
156+ self .generate_content (
154157 model = 'gemini-2.0-flash' ,
155158 contents = 'Some input' )
156159 self .otel .assert_does_not_have_event_named ('gen_ai.assistant.message' )
157160
158161 def test_records_metrics_data (self ):
159162 self .configure_valid_response ()
160- response = self .client . models . generate_content (
163+ response = self .generate_content (
161164 model = 'gemini-2.0-flash' ,
162165 contents = 'Some input' )
163166 self .otel .assert_has_metrics_data_named ('gen_ai.client.token.usage' )
0 commit comments