@@ -147,16 +147,16 @@ def assertErrorOperationDurationMetric(self, metric: Histogram, attributes: dict
147147 est_value_delta = 0.5 ,
148148 )
149149
150- def assertTokenUsageMetric (self , metric : Histogram ):
150+ def assertTokenUsageMetric (self , metric : Histogram , input_data_point = 24 , output_data_point = 4 ):
151151 self .assertEqual (metric .name , "gen_ai.client.token.usage" )
152152 self .assert_metric_expected (
153153 metric ,
154154 [
155155 self .create_histogram_data_point (
156156 count = 1 ,
157- sum_data_point = 24 ,
158- max_data_point = 24 ,
159- min_data_point = 24 ,
157+ sum_data_point = input_data_point ,
158+ max_data_point = input_data_point ,
159+ min_data_point = input_data_point ,
160160 attributes = {
161161 "gen_ai.operation.name" : "chat" ,
162162 "gen_ai.request.model" : OPENAI_TOOL_MODEL ,
@@ -169,9 +169,9 @@ def assertTokenUsageMetric(self, metric: Histogram):
169169 ),
170170 self .create_histogram_data_point (
171171 count = 1 ,
172- sum_data_point = 4 ,
173- max_data_point = 4 ,
174- min_data_point = 4 ,
172+ sum_data_point = output_data_point ,
173+ max_data_point = output_data_point ,
174+ min_data_point = output_data_point ,
175175 attributes = {
176176 "gen_ai.operation.name" : "chat" ,
177177 "gen_ai.request.model" : OPENAI_TOOL_MODEL ,
@@ -349,6 +349,10 @@ def test_function_calling_with_tools(self):
349349 )
350350 self .assertEqual (span .events , ())
351351
352+ operation_duration_metric , token_usage_metric = self .get_sorted_metrics ()
353+ self .assertOperationDurationMetric (operation_duration_metric )
354+ self .assertTokenUsageMetric (token_usage_metric , input_data_point = 140 , output_data_point = 19 )
355+
352356 def test_tools_with_capture_content (self ):
353357 # Redo the instrumentation dance to be affected by the environment variable
354358 OpenAIInstrumentor ().uninstrument ()
0 commit comments