open-telemetry / open-telemetry/opentelemetry-python-contrib
Amazon Bedrock (botocore) instrumentation does not capture prompt cache token usage
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
Describe your environment
opentelemetry-instrumentation-botocore: 0.61b0 (gap also present onmain)- Python 3.11; Amazon Bedrock
ConverseStream
What happened?
When invoking Amazon Bedrock with prompt caching
enabled, the spans drop the cache token usage. Bedrock returns
cacheReadInputTokens and cacheWriteInputTokens in the response usage,
but the instrumentation reads only inputTokens / outputTokens in
_converse_on_success (extensions/bedrock.py) — so
gen_ai.usage.cache_read.input_tokens and
gen_ai.usage.cache_creation.input_tokens are never emitted.
Net effect: any cost/usage analysis built on these spans is incomplete for
cached requests.
Expected behavior
When the Bedrock response usage includes cacheReadInputTokens /
cacheWriteInputTokens, the span should carry the corresponding OTel GenAI
semconv attributes gen_ai.usage.cache_read.input_tokens /
gen_ai.usage.cache_creation.input_tokens (both already defined in
opentelemetry-semantic-conventions).
Additional context
I have a fix ready and will open a PR.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in extensions/bedrock.py at _converse_on_success and inspect how the Bedrock response usage fields are mapped to span attributes. Confirm that cacheReadInputTokens and cacheWriteInputTokens produce the two named GenAI cache attributes; the issue is done when cached requests no longer lose those values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 39/100