File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
instrumentation-genai/opentelemetry-instrumentation-google-genai/tests/generate_content Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -63,3 +63,20 @@ def test_handles_multiple_ressponses(self):
6363 self .assertEqual (responses [1 ].text , "Second response" )
6464 choice_events = self .otel .get_events_named ("gen_ai.choice" )
6565 self .assertEqual (len (choice_events ), 2 )
66+
67+ def test_includes_token_counts_in_span_aggregated_from_responses (self ):
68+ # Configure multiple responses whose input/output tokens should be
69+ # accumulated together when summarizing the end-to-end request.
70+ #
71+ # Input: 1 + 3 + 5 => 4 + 5 => 9
72+ # Output: 2 + 4 + 6 => 6 + 6 => 12
73+ self .configure_valid_response (input_tokens = 1 , output_tokens = 2 )
74+ self .configure_valid_response (input_tokens = 3 , output_tokens = 4 )
75+ self .configure_valid_response (input_tokens = 5 , output_tokens = 6 )
76+
77+ self .generate_content (model = "gemini-2.0-flash" , contents = "Some input" )
78+
79+ self .otel .assert_has_span_named ("generate_content gemini-2.0-flash" )
80+ span = self .otel .get_span_named ("generate_content gemini-2.0-flash" )
81+ self .assertEqual (span .attributes ["gen_ai.usage.input_tokens" ], 9 )
82+ self .assertEqual (span .attributes ["gen_ai.usage.output_tokens" ], 12 )
You can’t perform that action at this time.
0 commit comments