feat(adk): emit cached token series on gen_ai token usage metric (#2669) - #2677
Open
MartinForReal wants to merge 2 commits into
Open
feat(adk): emit cached token series on gen_ai token usage metric (#2669)#2677MartinForReal wants to merge 2 commits into
MartinForReal wants to merge 2 commits into
Conversation
Record the OpenTelemetry GenAI-semconv gen_ai.client.token.usage metric from the Go ADK runtime using the native Prometheus client, served at /metrics. Labels follow the upstream Google ADK Python runtime so one dashboard works across both runtimes (gen_ai.token.type, gen_ai.request.model, gen_ai.response.model, gen_ai.provider.name, gen_ai.agent.name, gen_ai.operation.name, error.type). Recording and the scrape endpoint are gated default-OFF behind OTEL_METRICS_ENABLED, matching the existing OTEL_TRACING_ENABLED / OTEL_LOGGING_ENABLED gates. Signed-off-by: MartinForReal <fanshangxiang@gmail.com>
Signed-off-by: MartinForReal <fanshangxiang@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 2 of #2669: emit a cached token-type series on the existing
gen_ai.client.token.usagemetric so prompt-cache hits become aggregatable (gen_ai_token_type="cached").This change stacks on top of the token-usage histogram introduced in (#2673) — "feat(adk): expose gen_ai token usage Prometheus metric" — which must merge first.
What changes
gen_ai_client_token_usagehistogram.RecordTokenUsagerecords the cached prompt-token count when positive; zero/negative counts are skipped, matching the existing input/output behavior.recordTokenUsagein the A2A executor wiresUsageMetadata.CachedContentTokenCountthrough as the cached token count.Testing
CachedContentTokenCountemits agen_ai_token_type="cached"series valued at the cached count; partial events and absent/zero cached counts emit none).gofmt -lclean on all changed files;go build ./...,go vet ./adk/...,go test ./adk/pkg/a2a/...andgo test ./adk/pkg/telemetry/...pass.DCO
Signed-off-by: MartinForReal fanshangxiang@gmail.com
Refs: #2669, #2673