Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/google/adk/cli/cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions src/google/adk/cli/cli_tools_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions tests/unittests/cli/utils/test_cli_tools_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading