Immutable solution version
opentelemetry ValueError: "Token was created in a different Context" with ParallelAgent and LlmAgent
Complete solution
[aabmass (maintainer)]: This is an upstream opentelemetry/cpython interaction, not an exporter bug: async iterators trip "Token was created in a different Context" after ParallelAgent sub-agents finish. If your code uses an async iterator, apply the workaround in this CPython comment: https://github.com/python/cpython/issues/118944#issuecomment-2105661088.
opentelemetry ValueError: "Token was created in a different Context" with ParallelAgent and LlmAgent
[aabmass (maintainer)]: This is an upstream opentelemetry/cpython interaction, not an exporter bug: async iterators trip "Token was created in a different Context" after ParallelAgent sub-agents finish. If your code uses an async iterator, apply the workaround in this CPython comment: https://github.com/python/cpython/issues/118944#issuecomment-2105661088. Do not just swap startascurrentspan() for startspan(), that breaks span parent propagation.
Context from the issue
gh:google/adk-python#860: Issue google/adk-python#860 (closed, 27 comments): When using google.adk.agents.ParallelAgent with multiple google.adk.agents.LlmAgent instances as sub-agents, ValueError exceptions from the opentelemetry.context module are consistently logged. These errors occur after each sub-agent completes its processing. While the core functionality of the agents (e.g., LLM calls and output generation) appears to be unaffected, these errors create noise in the logs and suggest a potential issue with context management within the ADK framework or its interaction with opentelemetry. Steps to Reproduce: 1.
Evidence
Issue gh:google/adk-python#860: the reporter asked: Issue google/adk-python#860 (closed, 27 comments): When using google.adk.agents.ParallelAgent with multiple google.adk.agents.LlmAgent instances as sub-agents, ValueError exceptions from the opentelemetry.context module are consistently logged. These errors occur after each sub-agent completes its processing. While the core functionality of the agents (e.g., LLM calls and output generation) appears to be unaffected, these errors create noise in the logs and suggest a potential issue with context management within the ADK framework or its interaction with opentelemetry. Steps to Reproduce: 1. The verified answer was: [aabmass (maintainer)]: This is an upstream opentelemetry/cpython interaction, not an exporter bug: async iterators trip "Token was created in a different Context" after ParallelAgent sub-agents finish. If your code uses an async iterator, apply the workaround in this CPython comment: https://github.com/python/cpython/issues/118944#issuecomment-2105661088. Do not just swap startascurrentspan() for startspan(), that breaks span parent propagation. Evidence thread: https://github.com/google/adk-python/issues/860
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_y7If3_8MyC_6wRwdxIRx1A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">opentelemetry ValueError: "Token was created in a different Context" with ParallelAgent and LlmAgent <span>— Vectle</span></a>