From be5d1f59121c5255e6061a518a5abe9e3e3c0a17 Mon Sep 17 00:00:00 2001 From: A Vertex SDK engineer Date: Thu, 23 Oct 2025 10:35:12 -0700 Subject: [PATCH] feat: disable prompt/response content in ADK spans if telemetry env is set PiperOrigin-RevId: 823098467 --- .../vertex_adk/test_agent_engine_templates_adk.py | 4 ++-- vertexai/agent_engines/templates/adk.py | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/unit/vertex_adk/test_agent_engine_templates_adk.py b/tests/unit/vertex_adk/test_agent_engine_templates_adk.py index 2da0429c37..de672bc451 100644 --- a/tests/unit/vertex_adk/test_agent_engine_templates_adk.py +++ b/tests/unit/vertex_adk/test_agent_engine_templates_adk.py @@ -608,10 +608,10 @@ def test_span_content_capture_disabled_by_default(self): @mock.patch.dict( os.environ, {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true"} ) - def test_span_content_capture_enabled_with_env_var(self): + def test_span_content_capture_disabled_with_env_var(self): app = agent_engines.AdkApp(agent=_TEST_AGENT) app.set_up() - assert os.environ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS"] == "true" + assert os.environ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS"] == "false" @mock.patch.dict(os.environ) def test_span_content_capture_enabled_with_tracing(self): diff --git a/vertexai/agent_engines/templates/adk.py b/vertexai/agent_engines/templates/adk.py index 51331a7c2c..cd05dd46d3 100644 --- a/vertexai/agent_engines/templates/adk.py +++ b/vertexai/agent_engines/templates/adk.py @@ -641,14 +641,10 @@ def set_up(self): location = self._tmpl_attrs.get("location") os.environ["GOOGLE_CLOUD_LOCATION"] = location - content_enabled = os.getenv( - "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "false" - ).lower() in ("true", "1") - # Disable content capture in custom ADK spans unless: - # 1. User opted-in for content capture. - # 2. Or user enabled tracing explicitly with the old flag (this is to - # preserve compatibility with old behavior). - if self._tmpl_attrs.get("enable_tracing") or content_enabled: + # Disable content capture in custom ADK spans unless user enabled + # tracing explicitly with the old flag + # (this is to preserve compatibility with old behavior). + if self._tmpl_attrs.get("enable_tracing"): os.environ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS"] = "true" else: os.environ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS"] = "false"