google / google/adk-python

Support for Disabling or Extending Internal OpenTelemetry Tracing in Google ADK (Python)

オープン
#2,792 コメント 4 件 リアクション 9 件 担当者 1 名 @Jacksunwei が担当を希望しています GitHub で見る
needs review tracing
主要言語
Python
スター
21.5k
フォーク
4k
平均マージ
1日 14時間
マージ済み PR(30日)
37

説明

Hi ADK Team,

We are integrating Google ADK with a FastAPI microservice that uses OpenTelemetry for distributed tracing and log correlation. We’ve encountered persistent context propagation errors (e.g., ValueError: was created in a different Context) when both our application and ADK use OpenTelemetry, with async generators and multiprocessing.

Problem:

ADK manages its own OpenTelemetry tracer and context, but does not expose a public API to disable, configure, or extend this tracing.
This leads to context detachment errors and makes it impossible to unify or customize tracing across our stack.
We cannot add custom span attributes, propagate our own context, or inject a custom tracer/span processor/exporter.

Feature Request:

Please provide a way to disable ADK’s internal OpenTelemetry tracing, or
Allow users to inject their own OpenTelemetry tracer, span processor, or exporter, or
Expose hooks to add custom attributes and propagate context, or
Document a recommended pattern for integrating ADK tracing with application-level OpenTelemetry tracing in async/multiprocessing environments.
Use Case:

We want to achieve unified distributed tracing and logging across our FastAPI app and ADK agents, with custom attributes and context propagation, without context errors.

If there’s a workaround or undocumented config, please let us know.

Stack Trace
--------------
Failed to detach context Traceback (most recent call last): File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/trace/__init__.py", line 589, in use_span yield span File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line 1105, in start_as_current_span yield span File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/google/adk/runners.py", line 236, in run_async yield event GeneratorExit During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach _RUNTIME_CONTEXT.detach(token) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach self._current_context.reset(token) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ ValueError: at 0x148bdb580> was created in a different Context Failed to detach context Traceback (most recent call last): File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/trace/__init__.py", line 589, in use_span yield span File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line 1105, in start_as_current_span yield span File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/google/adk/agents/base_agent.py", line 224, in run_async yield event GeneratorExit During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach _RUNTIME_CONTEXT.detach(token) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach self._current_context.reset(token) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ ValueError: at 0x148bdbc80> was created in a different Context Failed to detach context Traceback (most recent call last): File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/trace/__init__.py", line 589, in use_span yield span File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line 1105, in start_as_current_span yield span File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 629, in _call_llm_async yield llm_response GeneratorExit During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach _RUNTIME_CONTEXT.detach(token) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "/.pyenv/versions/3.13.0/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach self._current_context.reset(token) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ ValueError: at 0x148bf0ec0> was created in a different Context

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。