Skip to content

Amazon Bedrock (botocore) instrumentation does not capture prompt cache token usage #4614

@vinigrazzioli-96

Description

@vinigrazzioli-96

Describe your environment

  • opentelemetry-instrumentation-botocore: 0.61b0 (gap also present on main)
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions