File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
vertexai/agent_engines/templates Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -457,6 +457,26 @@ def test_enable_tracing_warning(self, caplog):
457457 # app.set_up()
458458 # assert "enable_tracing=True but proceeding with tracing disabled" in caplog.text
459459
460+ @mock .patch .dict (os .environ )
461+ def test_span_content_capture_disabled_by_default (self ):
462+ app = agent_engines .AdkApp (agent = _TEST_AGENT )
463+ app .set_up ()
464+ assert os .environ ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS" ] == "false"
465+
466+ @mock .patch .dict (
467+ os .environ , {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT" : "true" }
468+ )
469+ def test_span_content_capture_enabled_with_env_var (self ):
470+ app = agent_engines .AdkApp (agent = _TEST_AGENT )
471+ app .set_up ()
472+ assert os .environ ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS" ] == "true"
473+
474+ @mock .patch .dict (os .environ )
475+ def test_span_content_capture_enabled_with_tracing (self ):
476+ app = agent_engines .AdkApp (agent = _TEST_AGENT , enable_tracing = True )
477+ app .set_up ()
478+ assert os .environ ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS" ] == "true"
479+
460480
461481def test_dump_event_for_json ():
462482 from google .adk .events import event
Original file line number Diff line number Diff line change @@ -575,6 +575,19 @@ def set_up(self):
575575 os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
576576 location = self ._tmpl_attrs .get ("location" )
577577 os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
578+
579+ content_enabled = os .getenv (
580+ "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT" , "false"
581+ ).lower () in ("true" , "1" )
582+ # Disable content capture in custom ADK spans unless:
583+ # 1. User opted-in for content capture.
584+ # 2. Or user enabled tracing explicitly with the old flag (this is to
585+ # preserve compatibility with old behavior).
586+ if self ._tmpl_attrs .get ("enable_tracing" ) or content_enabled :
587+ os .environ ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS" ] = "true"
588+ else :
589+ os .environ ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS" ] = "false"
590+
578591 if self ._tmpl_attrs .get ("enable_tracing" ):
579592 instrumentor_builder = (
580593 self ._tmpl_attrs .get ("instrumentor_builder" )
You can’t perform that action at this time.
0 commit comments