Skip to content

Add new cached token gen ai attribute to Google gen AI instrumentation#4313

Merged
aabmass merged 7 commits intoopen-telemetry:mainfrom
DylanRussell:cached_token_branch
Apr 23, 2026
Merged

Add new cached token gen ai attribute to Google gen AI instrumentation#4313
aabmass merged 7 commits intoopen-telemetry:mainfrom
DylanRussell:cached_token_branch

Conversation

@DylanRussell
Copy link
Copy Markdown
Contributor

Description

Sets the new gen_ai.usage.cache_read.input_tokens attribute on spans / events generated by the Google gen AI instrumentation when the experimental sem conv flag is set.. Also does some minor code cleanup..

I don't think the gen_ai.usage.cache_creation.input_tokens attribute makes sense for Gemini.. You can explicitly set a cache but there's no number of tokens associated with that: https://ai.google.dev/gemini-api/docs/caching#explicit-caching

Note that the sem conv says to include cached token in the input token count, which I believe we are already doing without this PR because we use prompt token count which IIUC is the total input tokens based on https://ai.google.dev/gemini-api/docs/tokens#count-tokens and https://github.com/googleapis/python-genai/blob/1fdb4b87aaec6e58b415168ea5893c0e901819a9/google/genai/types.py#L7306C4-L7307C1

Fixes #4159

Type of change

Please delete options that are not relevant.

  • [ x] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Unit tests

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • [x ] No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • [ x] Followed the style guidelines of this project
  • [ x] Changelogs have been updated
  • [ x] Unit tests have been added
  • [ x] Documentation has been updated

@DylanRussell DylanRussell requested a review from a team as a code owner March 6, 2026 20:33
@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall lgtm

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Apr 17, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Approved PRs in Python PR digest Apr 17, 2026
@lmolkova lmolkova removed the Stale label Apr 17, 2026
@aabmass aabmass merged commit cf0662d into open-telemetry:main Apr 23, 2026
751 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[google-genai] Add support for thinking tokens and cached tokens collection

4 participants