AI-471 Add Google ADK metrics sample - #530
Conversation
DABH
left a comment
There was a problem hiding this comment.
The design is right, and I checked the load-bearing part rather than assuming it: ADK runs AfterModelCallback synchronously on the Workflow goroutine (base_flow.go:783 -> :804, no goroutine), so capturing workflow.GetMetricsHandler(ctx) at workflow.go:24 is legal, and .WithTags preserves the replay-aware wrapper. Choosing that over sdktally.ScopeFromHandler is the one decision that makes this replay-safe, and contrib/tally's handler.go:54-56 warns about exactly the trap you avoided. Counter semantics are right too — TemporalModel.GenerateContent yields one aggregated response per turn, and Activity retries are invisible to the Workflow, so model_calls is genuinely one-per-turn with no retry inflation.
Two things that aren't tied to a line in this diff:
The sample isn't registered anywhere. The root README.md:176-181 Google ADK bullet names all three existing scenarios and links them; googleadk/README.md:23-37 lists four. Neither mentions metrics/, and this diff touches only the five files under googleadk/metrics/, so there is no path to this sample from any index. Extending the root bullet:
signal), a [continue-as-new chat](./googleadk/chat), and [model-usage
metrics](./googleadk/metrics).
and a fifth bullet in googleadk/README.md:
- **[metrics/](metrics)** — records per-model-call token usage from
`LLMResponse.UsageMetadata` onto Temporal's replay-aware Workflow metrics
handler, exported via Prometheus.CI hasn't actually validated any of this. build-and-test failed at staticcheck on a pre-existing SA1019 in temporal-fixtures/rainbow-statuses/starter/main.go:47, and since Makefile:57 is ci-build: staticcheck errcheck workflowcheck bins test, the abort means errcheck, workflowcheck, bins and test never ran on this branch. I ran all five locally and they're green, so nothing is hiding — but the green-looking gate here is worth knowing about, and it'll keep failing for unrelated reasons until that fixture is fixed separately.
faa6a92 to
f759656
Compare
This PR adds a Google ADK sample that exports successful model-call and token-usage metrics through Temporal’s replay-aware Workflow metrics handler. It includes a Prometheus worker, starter, and API-key-free tests for exact metric values and missing usage metadata.