Repository navigation
feat(adk): expose gen_ai token usage Prometheus metric - #2673
Open
MartinForReal wants to merge 1 commit into
Open
MartinForReal wants to merge 1 commit into
MartinForReal wants to merge 1 commit into
Conversation
MartinForReal
force-pushed
the
feat-go-token-metrics
branch
from
September 7, 2026 08:20
aa27d18 to
38a5289
Compare
Author
|
Hi @supreme-gg-gg, friendly ping for review when you have a moment. This exposes the gen_ai token usage Prometheus metric for the Go ADK runtime. Ready for another look. Thanks! |
MartinForReal
force-pushed
the
feat-go-token-metrics
branch
from
September 23, 2026 09:13
4f575a9 to
353d7be
Compare
MartinForReal
force-pushed
the
feat-go-token-metrics
branch
2 times, most recently
from
October 8, 2026 08:36
efefd87 to
7bde0e6
Compare
MartinForReal
force-pushed
the
feat-go-token-metrics
branch
from
October 19, 2026 04:08
7bde0e6 to
39c1803
Compare
Record the GenAI-semconv gen_ai.client.token.usage histogram from the Go ADK runtime with the native Prometheus client, served at /metrics behind the default-OFF OTEL_METRICS_ENABLED gate. 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), and token counts are clamped to the int32 range the metric field carries. Signed-off-by: Shangxiang Fan (from Dev Box) <shafan@microsoft.com>
MartinForReal
force-pushed
the
feat-go-token-metrics
branch
from
October 23, 2026 11:50
39c1803 to
0c1451b
Compare
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.
What
Implements the GenAI token-usage metrics observability gap from #2148 for the Go ADK runtime. The Go ADK (
google.golang.org/adk/v2) ships spans only, no metric instruments, so kagent supplies the stdlib Prometheus instrument itself, in the shape of the open/dirty #2149 but rebuilt from scratch against today'sgo/adksource and aligned with the Python runtime's attribute set per #2458.How
pkg/telemetry/metrics.go— agen_ai_client_token_usagePrometheus histogram (semconvgen_ai.client.token.usage, semconv-recommended buckets) on the default registry.gen_ai_token_type(input/output),gen_ai_request_model,gen_ai_response_model(falls back to request model),gen_ai_provider_name(semconv well-known value viaSemconvProviderName),gen_ai_agent_name,gen_ai_operation_name(chat),error_type./metricsendpoint are default-OFF behindOTEL_METRICS_ENABLED=true, matching the existingOTEL_TRACING_ENABLED/OTEL_LOGGING_ENABLEDgates.pkg/a2a/server/server.go— serves/metricson the A2A mux when the gate is on, excluded from request tracing/span flushing.pkg/a2a/executor.go— records token usage from the ADKAfterEventCallback: skips partial (streaming) events so one observation is recorded per LLM call;input = PromptTokenCount,output = CandidatesTokenCount + ThoughtsTokenCountfromUsageMetadata.cmd/main.go/pkg/config— model + provider labels resolved at startup; agent name fromAppName.docs/genai-token-metrics.md— documents the metric, labels, gating, and scraping.Testing
go build ./adk/...,go vet, and golangci-lint (repo config) are clean.go test -racepasses for the changed packages (telemetry, a2a, a2a/server, config).metrics_test.go(record / skip-zero / disable-gate / response-model fallback / labels / provider-name mapping / /metrics handler) andexecutor_metrics_test.go(partial events not double-counted, per-LLM-call aggregation).Notes / decisions
go/core/internal/controller/translator/agent/manifest_builder.go, which no longer exists onmainafter the controller/runtime rework. That path was dropped rather than reinvented; operators can addprometheus.io/*annotations and this is documented. Flag if you want the annotation automation wired against the current runtime-provisioning location.make -C go lintcould not be run here:makeand the kube-api-linter plugin are unavailable in this environment. Lint was run with the repo's.golangci.yamlminus the plugin (0 issues); kube-apilinter only lintsapi/v1alphaCRD paths, untouched here.Refs: #2148