You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
feat(cli): add otel_to_cloud flag to adk deploy agent_engine command
Co-authored-by: Wiktoria Walczak <wwalczak@google.com> PiperOrigin-RevId: 858546581
This commit is contained in:
committed by
Copybara-Service
parent
69ad605bc4
commit
21f63f66ee
@@ -689,6 +689,7 @@ def to_agent_engine(
|
||||
adk_app: str,
|
||||
staging_bucket: Optional[str] = None,
|
||||
trace_to_cloud: Optional[bool] = None,
|
||||
otel_to_cloud: Optional[bool] = None,
|
||||
api_key: Optional[str] = None,
|
||||
adk_app_object: Optional[str] = None,
|
||||
agent_engine_id: Optional[str] = None,
|
||||
@@ -733,6 +734,8 @@ def to_agent_engine(
|
||||
staging_bucket (str): Deprecated. This argument is no longer required or
|
||||
used.
|
||||
trace_to_cloud (bool): Whether to enable Cloud Trace.
|
||||
otel_to_cloud (bool): Whether to enable exporting OpenTelemetry signals
|
||||
to Google Cloud.
|
||||
api_key (str): Optional. The API key to use for Express Mode.
|
||||
If not provided, the API key from the GOOGLE_API_KEY environment variable
|
||||
will be used. It will only be used if GOOGLE_GENAI_USE_VERTEXAI is true.
|
||||
@@ -910,6 +913,14 @@ def to_agent_engine(
|
||||
if 'GOOGLE_API_KEY' in env_vars:
|
||||
api_key = env_vars['GOOGLE_API_KEY']
|
||||
click.echo(f'api_key set by GOOGLE_API_KEY in {env_file}')
|
||||
if otel_to_cloud:
|
||||
if 'GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY' in env_vars:
|
||||
click.secho(
|
||||
'Ignoring GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY in .env'
|
||||
' as `--otel_to_cloud` was explicitly passed and takes precedence',
|
||||
fg='yellow',
|
||||
)
|
||||
env_vars['GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY'] = 'true'
|
||||
if env_vars:
|
||||
if 'env_vars' in agent_config:
|
||||
click.echo(
|
||||
|
||||
@@ -1751,6 +1751,14 @@ def cli_migrate_session(
|
||||
default=None,
|
||||
help="Optional. Whether to enable Cloud Trace for Agent Engine.",
|
||||
)
|
||||
@click.option(
|
||||
"--otel_to_cloud",
|
||||
type=bool,
|
||||
is_flag=True,
|
||||
show_default=True,
|
||||
default=None,
|
||||
help="Optional. Whether to enable OpenTelemetry for Agent Engine.",
|
||||
)
|
||||
@click.option(
|
||||
"--display_name",
|
||||
type=str,
|
||||
@@ -1842,6 +1850,7 @@ def cli_deploy_agent_engine(
|
||||
staging_bucket: Optional[str],
|
||||
agent_engine_id: Optional[str],
|
||||
trace_to_cloud: Optional[bool],
|
||||
otel_to_cloud: Optional[bool],
|
||||
api_key: Optional[str],
|
||||
display_name: str,
|
||||
description: str,
|
||||
@@ -1872,6 +1881,7 @@ def cli_deploy_agent_engine(
|
||||
region=region,
|
||||
agent_engine_id=agent_engine_id,
|
||||
trace_to_cloud=trace_to_cloud,
|
||||
otel_to_cloud=otel_to_cloud,
|
||||
api_key=api_key,
|
||||
adk_app_object=adk_app_object,
|
||||
display_name=display_name,
|
||||
|
||||
@@ -410,6 +410,38 @@ def test_cli_deploy_agent_engine_success(
|
||||
assert called_kwargs.get("region") == "us-central1"
|
||||
|
||||
|
||||
# cli deploy agent_engine with --otel_to_cloud
|
||||
def test_cli_deploy_agent_engine_otel_to_cloud_success(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Successful path should call cli_deploy.to_agent_engine with --otel_to_cloud."""
|
||||
rec = _Recorder()
|
||||
monkeypatch.setattr(cli_tools_click.cli_deploy, "to_agent_engine", rec)
|
||||
|
||||
agent_dir = tmp_path / "agent_ae"
|
||||
agent_dir.mkdir()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli_tools_click.main,
|
||||
[
|
||||
"deploy",
|
||||
"agent_engine",
|
||||
"--project",
|
||||
"test-proj",
|
||||
"--region",
|
||||
"us-central1",
|
||||
"--otel_to_cloud",
|
||||
str(agent_dir),
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert rec.calls, "cli_deploy.to_agent_engine must be invoked"
|
||||
called_kwargs = rec.calls[0][1]
|
||||
assert called_kwargs.get("project") == "test-proj"
|
||||
assert called_kwargs.get("region") == "us-central1"
|
||||
assert called_kwargs.get("otel_to_cloud")
|
||||
|
||||
|
||||
# cli deploy gke
|
||||
def test_cli_deploy_gke_success(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
|
||||
Reference in New Issue
Block a user