ITADN

[bug] google-adk: sub-agent spans get wrong session.id when using AgentTool

#3117OpenMrOrz 创建于 2026-05-17
bugtriage
M
MrOrzcommented
### **Describe the bug** When using `openinference-instrumentation-google-adk`, spans generated during sub-agent execution (invoked via `AgentTool`) are stamped with an incorrect `session.id`. Instead of inheriting the `session_id` passed to the top-level `Runner`, sub-agent spans are stamped with an ADK-internal sub-session UUID. This causes traces to be split across different sessions in backends like Langfuse or Arize Phoenix. ### **To Reproduce** I have created a minimal reproduction repository: https://github.com/MrOrz/openinference-google-adk-session-id-bug 1. Clone the repo. 2. Install dependencies: `uv sync`. 3. Set `GOOGLE_API_KEY` in `.env`. 4. Run the PoC: `uv run python poc.py`. 5. Observe the output table where `agent_run [sub_agent]` and its child `call_llm` spans have a different `session.id` than the root span. ### **Expected behavior** All spans within the same trace, including those from sub-agents invoked via `AgentTool`, should share the same `session.id` provided to the initial `runner.run_async()` call. ### **Actual behavior** ```text ────────────────────────────────────────────────────────────────────── SPAN NAME session.id ────────────────────────────────────────────────────────────────────── call_llm 4bad3789-fdf2-45ad-bb14-fab0e75dc610 ✗ BUG agent_run [sub_agent] 4bad3789-fdf2-45ad-bb14-fab0e75dc610 ✗ BUG invocation [poc-app] known-session-id-abc123 execute_tool sub_agent known-session-id-abc123 call_llm known-session-id-abc123 agent_run [root_agent] known-session-id-abc123 invocation [poc-app] known-session-id-abc123 ────────────────────────────────────────────────────────────────────── ``` ### **Desktop (please complete the following information):** - OS: macOS (darwin) - Version: openinference-instrumentation-google-adk==0.1.13, google-adk==1.31.1 ### **Additional context** **Root Cause Analysis:** In `openinference/instrumentation/google_adk/_wrappers.py`, the `_RunnerRunAsync.__call__` method extracts the `session_id` from the `kwargs` passed to ADK's `Runner.run_async`. When ADK invokes a sub-agent, it passes a newly generated internal sub-session UUID as the `session_id` argument. The instrumentation then uses this value to overwrite the `session.id` attribute, even if a valid user-facing `session.id` is already present in the OpenTelemetry context from the parent runner. **Proposed Fix:** The instrumentation should check if a `session.id` already exists in the ambient context before overwriting it with the `session_id` argument from `kwargs`.
1 条评论