Repository navigation
feat(adk): trace workflow nodes and tool calls - #895
Merged
Abhijeet Prasad (AbhiPrasad) merged 2 commits intoOct 8, 2026
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Abhijeet Prasad (AbhiPrasad)
requested review from
Stephen Belanger (Qard) and
Andrew Kent (realark)
October 8, 2026 16:52
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ac39ce4d0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
Stephen Belanger (Qard)
approved these changes
Oct 8, 2026
Abhijeet Prasad (AbhiPrasad)
deleted the
abhi/instrument-adk-workflows-9245626f
branch
October 8, 2026 18:00
Abhijeet Prasad (AbhiPrasad)
added a commit
that referenced
this pull request
Oct 9, 2026
## AI Summary With `braintrust.auto_instrument()`, every Gemini request made through Google ADK produced two nested `llm` spans with the same token usage: ADK's `llm_call [...]` and Google GenAI's `generate_content`. Trace summaries counted the request's tokens and LLM calls twice. ADK always sends model calls through a separately instrumented provider client, so this PR lets that integration own the `llm` span and its usage. The JS SDK's ADK plugin and our pydantic-ai, DSPy and LlamaIndex integrations already work this way. - **ADK span:** `llm_call [...]` is now a `task` span and no longer logs token metrics or usage metadata. It keeps its input, output, model/provider/tools metadata, `llm_call_type` and `time_to_first_token`. GenAI's `generate_content` remains the only `llm` span and carries the full usage: tool-use prompt tokens, reasoning tokens and `usage_by_modality`. - **`setup_adk()`:** it now also enables the Google GenAI integration, so `setup_adk()`-only users still get a Gemini `llm` span with tokens. The import happens inside the function, so the `wrap_*` helpers don't pay for it. `auto_instrument()` enables both already, and `auto_instrument(google_genai=False)` still turns GenAI off. Fixes #896 (SDK-525). ## Before / after One Gemini request replaying the recorded `test_adk_captures_metrics` response, each mode in a fresh process: | Mode | Before: `llm` spans | Before: tokens (prompt / completion) | After: `llm` spans | After: tokens (prompt / completion) | |---|---|---|---|---| | `auto_instrument()` (reported case) | 2 | 58 / 10 | 1 | 29 / 5 | | `setup_adk()` only | 1 (ADK) | 29 / 5 | 1 (GenAI) | 29 / 5 | | GenAI only | 1 | 29 / 5 | 1 | 29 / 5 | ## Behavior changes - Spans named `llm_call [...]` are now `task` spans. Queries filtering ADK spans by `type = llm` will match GenAI's `generate_content` instead. - ADK agents on non-Gemini models (LiteLlm, Claude, custom model classes) only get token usage when that provider's integration is on. `auto_instrument()` turns them on; with `setup_adk()` alone, those calls no longer get token metrics. The `setup_adk()` docstring now says so. - Users who call only the manual `wrap_flow()` helper, without `setup_adk()`, need GenAI instrumentation enabled to keep token metrics. ## Tests No cassettes were re-recorded. GenAI instrumentation doesn't change the outgoing HTTP request, so the existing recordings replay unchanged. - **`auto_test_scripts/test_auto_adk.py`:** runs the reported `auto_instrument()` scenario in a subprocess against the recorded Gemini response. It asserts that only `generate_content` carries usage and that its parent is a `task`-typed `llm_call`. - **`test_adk_captures_metrics`:** covers the `setup_adk()`-only path with the same assertions. - **Other ADK tests:** they now use a shared `_assert_provider_owns_llm_spans` helper, which checks one GenAI `llm` child per ADK model call, with only those children carrying usage. Tests that inspect ADK's request shape select the `llm_call` spans by name. - **Red / green:** both regression tests failed before the fix, with two `llm` spans of 29/5 tokens each. Against `main`'s source, 7 tests fail; with the fix, all pass. ## Validation - **`test_google_adk(latest)`:** 18 passed, including the workflow tests from #895, which this PR is rebased onto. - **`test_google_adk(2.6.3)` and `test_google_adk(1.14.1)`:** 15 passed, 3 skipped each; the skips are the workflow-only tests. The 1.14.1 session resolves `google-genai` 1.75.0, which GenAI instrumentation supports. - **`test_google_genai(latest)`:** 43 passed, 2 skipped. - **`test_core -k lazy`:** passed. Importing `braintrust.integrations.adk` still loads neither `google.genai` nor `google.adk`. - **Lint:** `make lint` and `make pylint` pass. - **Not tested live:** nothing ran against the live Gemini API or the Braintrust dashboard. All runs replay recorded responses. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- sfk:bot-coauthor --> Co-authored by @starfolkai[bot] Co-authored-by: Claude Opus 5.5 <noreply@anthropic.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.
_ToolNodecalls, including arguments and outputs.Closes #863.