Repository navigation
fix(instrumentation-bedrock): safely compute titan total tokens when output tokens are missing - #1039
Yogesh0314 wants to merge 1 commit into
Conversation
…output tokens are missing
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughTitan streaming and non-streaming responses now omit output-token usage attributes when output counts are unavailable. Total-token usage still includes the input count, treating a missing output count as zero. Tests cover both missing and present output counts. ChangesTitan token usage
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to This change stops Titan embedding spans from reporting a NaN total token count when no output count is present. The output-token attribute is now left out in that case. No merge-blocking risk was found. Security Architecture ReviewSecurity architecture risk: ⚪ Minimal · up to The change corrects token-count reporting without adding access, privileges, sensitive content collection, or new dependencies. Responses containing both counts retain their existing behavior. No material security risk was identified in the changed flow. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Comment |
Description
Fixes #1031.
For Amazon Titan embedding responses (e.g.
amazon.titan-embed-text-v2:0),inputTextTokenCountis present in the response but output token counts are absent. Computing total tokens asinputTextTokenCount + titanOutputTokensresulted innumber + undefined = NaN, which was serialized as"NaN"in exported span attributes.Changes
packages/instrumentation-bedrock/src/instrumentation.ts:0when calculatingGEN_AI_USAGE_TOTAL_TOKENSfor Amazon Titan responses (titanInputTokens + (titanOutputTokens ?? 0)).ATTR_GEN_AI_USAGE_OUTPUT_TOKENSif output tokens are defined.totalOutputTextTokenCountis absent.packages/instrumentation-bedrock/tests/titan-tokens.test.ts.Testing
@traceloop/instrumentation-bedrock(all passing).Summary by CodeRabbit