[bot] Bedrock Converse prompt caching metrics (cacheReadInputTokens, cacheWriteInputTokens) not captured
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 70/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- aws, java
调研方向
从 InstrumentationSemConv.java 中的 tagBedrockResponse() 开始,然后针对流式路径跟踪 BraintrustBedrockInterceptor.java 中的 parseTokenUsage() 和 buildConverseJson()。在 BraintrustAWSBedrockTest.java 中使用包含 Bedrock prompt-cache 使用量字段的响应添加覆盖;当两个 Converse 路径都保留并捕获 cacheReadInputTokens、cacheWriteInputTokens 和 cacheDetails 时即表示完成。
由索引模型根据 Issue 内容生成。
描述
Summary
The Bedrock Converse instrumentation extracts inputTokens, outputTokens, and totalTokens from the response usage object, but silently drops the prompt caching fields cacheReadInputTokens, cacheWriteInputTokens, and cacheDetails. These fields are returned by the Bedrock Converse API when prompt caching is active and are important for understanding cache hit rates and cost savings.
Both the non-streaming (Converse) and streaming (ConverseStream) paths are affected.
What is missing
Non-streaming path
In InstrumentationSemConv.tagBedrockResponse() (lines 350–357), only three usage fields are extracted:
if (usage.has("inputTokens")) metrics.put("prompt_tokens", usage.get("inputTokens"));
if (usage.has("outputTokens")) metrics.put("completion_tokens", usage.get("outputTokens"));
if (usage.has("totalTokens")) metrics.put("tokens", usage.get("totalTokens"));
The following fields from the Bedrock usage object are never extracted:
cacheReadInputTokens— tokens served from the prompt cachecacheWriteInputTokens— tokens written to the prompt cachecacheDetails— array of per-checkpoint cache details including TTL
Streaming path
In BraintrustBedrockInterceptor.TeeingSubscriber.parseTokenUsage() (lines 362–379), only inputTokens and outputTokens are parsed from the metadata event payload. Cache token fields in the same payload are ignored. The buildConverseJson() method (lines 385–410) then constructs a synthetic response with only inputTokens, outputTokens, and totalTokens — cache fields are lost before they reach tagBedrockResponse.
A real Converse response with prompt caching looks like:
"usage": {
"inputTokens": 1200,
"outputTokens": 350,
"totalTokens": 1550,
"cacheReadInputTokens": 800,
"cacheWriteInputTokens": 400,
"cacheDetails": [
{ "inputTokens": 800, "ttl": "5m" }
]
}
Today, only inputTokens, outputTokens, and totalTokens are captured. The cache fields are silently dropped.
For comparison, the Google GenAI handler in this repo already extracts cachedContentTokenCount as prompt_cached_tokens (line 142–146 of BraintrustApiClient.java), showing that cache token extraction is an established pattern here. Similar gaps for Anthropic (#57) and OpenAI (#58, #70) cache tokens have already been filed.
Braintrust docs status
- Braintrust lists AWS Bedrock as a supported cloud provider at https://www.braintrust.dev/docs/integrations/ai-providers
- The Bedrock-specific docs page does not mention prompt caching or cache token metrics: not_found
Upstream sources
- AWS Bedrock prompt caching docs: https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html — GA feature, documents
cacheReadInputTokensandcacheWriteInputTokensin Converse response usage - Bedrock Converse API reference: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html —
TokenUsageincludescacheReadInputTokens,cacheWriteInputTokens,cacheDetails - Supported models: Claude Opus 4, Claude 3.7 Sonnet (GA); Claude 3.5 Sonnet v2 (Preview); Amazon Nova (automatic caching)
Local files inspected
braintrust-sdk/src/main/java/dev/braintrust/instrumentation/InstrumentationSemConv.java— lines 350–357 (tagBedrockResponse: onlyinputTokens,outputTokens,totalTokensextracted from usage)braintrust-sdk/instrumentation/aws_bedrock_2_30_0/src/main/java/dev/braintrust/instrumentation/awsbedrock/v2_30_0/BraintrustBedrockInterceptor.java— lines 362–379 (parseTokenUsage: onlyinputTokensandoutputTokensparsed); lines 385–410 (buildConverseJson: synthetic response omits cache fields)braintrust-sdk/instrumentation/aws_bedrock_2_30_0/src/test/java/dev/braintrust/instrumentation/awsbedrock/v2_30_0/BraintrustAWSBedrockTest.java— no test exercises prompt caching responsesbraintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustApiClient.java— lines 142–146 (GenAI handler already extractscachedContentTokenCountasprompt_cached_tokens)
- 主要语言
- Java
- 星标
- 21
- 派生
- 5
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
braintrustdata/braintrust-sdk-java 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 68/100
查看 braintrustdata/braintrust-sdk-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
apache/rocketmq-dashboard#6610 ·
维护者通常 3 天内回复
-
Citationcount column sorts alphabetically instead of numerically可能已有人在做 @kpunia306 今天认领。 未关闭status: needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
`RedisList.reversed()` view returns an empty `range` and `trim` removes all elements可能已有人在做 @CCCLL 今天认领。 未关闭status: waiting-for-triage
难度 2/5 1-3 小时 新手友好度 72/100
spring-projects/spring-data-redis#3461 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
javapathfinder/jpf-core#649 ·
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
devops-thiago/ThrillhouseBot#1093 ·
维护者通常 1 天内回复