Conversation
✅MegaLinter analysis: Success
See detailed reports in MegaLinter artifacts
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1682 +/- ##
==========================================
+ Coverage 81.85% 81.92% +0.07%
==========================================
Files 214 214
Lines 25683 25813 +130
Branches 4076 4090 +14
==========================================
+ Hits 21022 21147 +125
- Misses 3264 3265 +1
- Partials 1397 1401 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* Add OpenAI token counts. * Add token counts to langchain + openai tests. * Remove unused expected events. * Linting * Add OpenAI token counts. * Add token counts to langchain + openai tests. * Remove unused expected events. * [MegaLinter] Apply linters fixes --------- Co-authored-by: Tim Pansino <timpansino@gmail.com>
* Add bedrock token counting. * [MegaLinter] Apply linters fixes * Add bedrock token counting. * Add safeguards when grabbing token counts. * Remove extra None defaults. * Cleanup default None checks. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Add response token count logic to Gemini instrumentation. * Update token counting util functions. * Linting * Add response token count logic to Gemini instrumentation. * Update token counting util functions. * [MegaLinter] Apply linters fixes * Bump tests. --------- Co-authored-by: Tim Pansino <timpansino@gmail.com>
a6e4630 to
35c85ad
Compare
JiwaniZakir
left a comment
There was a problem hiding this comment.
In create_chat_completion_message_event, the all_token_counts parameter is added to the signature and checked for truthiness, but its value is never actually used — both the request message (line ~231) and response message (line ~274) unconditionally set "token_count": 0 whenever the flag is truthy. This looks like a bug where the actual per-message token count should be extracted from all_token_counts rather than hardcoded to zero. If all_token_counts is a dict or list keyed by message index, the lookup logic is missing entirely.
Additionally, extract_bedrock_titan_embedding_model_response sets only response.usage.total_tokens (equal to inputTextTokenCount), while the text model response handler sets all three — prompt_tokens, completion_tokens, and total_tokens. The inconsistency is reasonable for embeddings (no output), but it would be worth a comment clarifying the intentional omission of prompt_tokens and completion_tokens to avoid confusion for future maintainers.
In extract_bedrock_titan_text_model_streaming_response, the accumulation pattern (bedrock_attrs.get(..., 0) + value) assumes invocation metrics may appear across multiple chunks, but amazon-bedrock-invocationMetrics is typically only present in the final chunk — so for most chunks prompt_tokens and completion_tokens will be 0, meaning the accumulation adds unnecessary overhead without risk of double-counting. A guard checking whether the metrics key exists before updating would make the intent clearer.

This PR includes changes to send token counts pulled from LLM response objects directly from the agent.