Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[bot] Bedrock Converse prompt caching metrics (cacheReadInputTokens, cacheWriteInputTokens) not captured

Đang mở
#88 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
aws, java
Lĩnh vực
observability

Hướng nghiên cứu

Bắt đầu trong InstrumentationSemConv.java tại tagBedrockResponse(), sau đó lần theo parseTokenUsage() và buildConverseJson() trong BraintrustBedrockInterceptor.java cho luồng streaming. Thêm coverage trong BraintrustAWSBedrockTest.java bằng một response có các trường usage của prompt cache của Bedrock; hoàn tất khi cả hai luồng Converse đều giữ lại và thu thập cacheReadInputTokens, cacheWriteInputTokens và cacheDetails.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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 cache
  • cacheWriteInputTokens — tokens written to the prompt cache
  • cacheDetails — 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

Upstream sources

Local files inspected

  • braintrust-sdk/src/main/java/dev/braintrust/instrumentation/InstrumentationSemConv.java — lines 350–357 (tagBedrockResponse: only inputTokens, outputTokens, totalTokens extracted 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: only inputTokens and outputTokens parsed); 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 responses
  • braintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustApiClient.java — lines 142–146 (GenAI handler already extracts cachedContentTokenCount as prompt_cached_tokens)
Ngôn ngữ chính
Java
Star
21
Fork
5
Merge trung bình
2 ngày 7 giờ
Pull request đã merge (30 ngày)
8

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của braintrustdata/braintrust-sdk-java

Tất cả issue của braintrustdata/braintrust-sdk-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.