Skip to content

Commit a6a7c8a

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: Add warning if tracing is enabled but telemetry API is disabled.
PiperOrigin-RevId: 827478823
1 parent 7c8c218 commit a6a7c8a

File tree

2 files changed

+56
-0
lines changed
  • vertexai
    • agent_engines/templates
    • preview/reasoning_engines/templates

2 files changed

+56
-0
lines changed

vertexai/agent_engines/templates/adk.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@
9494

9595
_DEFAULT_APP_NAME = "default-app-name"
9696
_DEFAULT_USER_ID = "default-user-id"
97+
_TELEMETRY_API_DISABLED_WARNING = (
98+
"Tracing integration for Agent Engine has migrated to a new API.\n"
99+
"The 'telemetry.googleapis.com' has not been enabled in project %s. \n"
100+
"**Impact:** Until this API is enabled, telemetry data will not be stored."
101+
"\n"
102+
"**Action:** Please enable the API by visiting "
103+
"https://console.developers.google.com/apis/api/telemetry.googleapis.com/overview?project=%s."
104+
"\n"
105+
"(If you enabled this API recently, you can safely ignore this warning.)"
106+
)
97107

98108

99109
def get_adk_version() -> Optional[str]:
@@ -743,6 +753,9 @@ def set_up(self):
743753

744754
custom_instrumentor = self._tmpl_attrs.get("instrumentor_builder")
745755

756+
if self._tmpl_attrs.get("enable_tracing"):
757+
self._warn_if_telemetry_api_disabled()
758+
746759
if self._tmpl_attrs.get("enable_tracing") is False:
747760
_warn(
748761
(
@@ -1550,3 +1563,18 @@ def _tracing_enabled(self) -> bool:
15501563
and enable_telemetry is True
15511564
and is_version_sufficient("1.17.0")
15521565
)
1566+
1567+
def _warn_if_telemetry_api_disabled(self):
1568+
"""Warn if telemetry API is disabled."""
1569+
try:
1570+
import google.auth.transport.requests
1571+
import google.auth
1572+
except (ImportError, AttributeError):
1573+
return
1574+
credentials, project = google.auth.default()
1575+
session = google.auth.transport.requests.AuthorizedSession(
1576+
credentials=credentials
1577+
)
1578+
r = session.post("https://telemetry.googleapis.com/v1/traces", data=None)
1579+
if "Telemetry API has not been used in project" in r.text:
1580+
_warn(_TELEMETRY_API_DISABLED_WARNING % (project, project))

vertexai/preview/reasoning_engines/templates/adk.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@
9696

9797
_DEFAULT_APP_NAME = "default-app-name"
9898
_DEFAULT_USER_ID = "default-user-id"
99+
_TELEMETRY_API_DISABLED_WARNING = (
100+
"Tracing integration for Agent Engine has migrated to a new API.\n"
101+
"The 'telemetry.googleapis.com' has not been enabled in project %s. \n"
102+
"**Impact:** Until this API is enabled, telemetry data will not be stored."
103+
"\n"
104+
"**Action:** Please enable the API by visiting "
105+
"https://console.developers.google.com/apis/api/telemetry.googleapis.com/overview?project=%s."
106+
"\n"
107+
"(If you enabled this API recently, you can safely ignore this warning.)"
108+
)
99109

100110

101111
def get_adk_version() -> Optional[str]:
@@ -663,6 +673,9 @@ def set_up(self):
663673
else:
664674
os.environ["ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS"] = "false"
665675

676+
if self._tmpl_attrs.get("enable_tracing"):
677+
self._warn_if_telemetry_api_disabled()
678+
666679
if self._tmpl_attrs.get("enable_tracing") is False:
667680
_warn(
668681
(
@@ -1486,3 +1499,18 @@ def _tracing_enabled(self) -> bool:
14861499
and enable_telemetry is True
14871500
and is_version_sufficient("1.17.0")
14881501
)
1502+
1503+
def _warn_if_telemetry_api_disabled(self):
1504+
"""Warn if telemetry API is disabled."""
1505+
try:
1506+
import google.auth.transport.requests
1507+
import google.auth
1508+
except (ImportError, AttributeError):
1509+
return
1510+
credentials, project = google.auth.default()
1511+
session = google.auth.transport.requests.AuthorizedSession(
1512+
credentials=credentials
1513+
)
1514+
r = session.post("https://telemetry.googleapis.com/v1/traces", data=None)
1515+
if "Telemetry API has not been used in project" in r.text:
1516+
_warn(_TELEMETRY_API_DISABLED_WARNING % (project, project))

0 commit comments

Comments
 (0)