Skip to content

Commit 62fa4e5

Browse files
Wiktoria Walczakcopybara-github
authored andcommitted
feat(cli): add otel_to_cloud flag to adk deploy cloud_run and adk deploy gke command
Co-authored-by: Wiktoria Walczak <[email protected]> PiperOrigin-RevId: 854087382
1 parent 4dd5434 commit 62fa4e5

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/google/adk/cli/cli_deploy.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
6565
EXPOSE {port}
6666
67-
CMD adk {command} --port={port} {host_option} {service_option} {trace_to_cloud_option} {allow_origins_option} {a2a_option} "/app/agents"
67+
CMD adk {command} --port={port} {host_option} {service_option} {trace_to_cloud_option} {otel_to_cloud_option} {allow_origins_option} {a2a_option} "/app/agents"
6868
"""
6969

7070
_AGENT_ENGINE_APP_TEMPLATE: Final[str] = """
@@ -487,6 +487,7 @@ def to_cloud_run(
487487
temp_folder: str,
488488
port: int,
489489
trace_to_cloud: bool,
490+
otel_to_cloud: bool,
490491
with_ui: bool,
491492
log_level: str,
492493
verbosity: str,
@@ -523,6 +524,8 @@ def to_cloud_run(
523524
temp_folder: The temp folder for the generated Cloud Run source files.
524525
port: The port of the ADK api server.
525526
trace_to_cloud: Whether to enable Cloud Trace.
527+
otel_to_cloud: Whether to enable exporting OpenTelemetry signals
528+
to Google Cloud.
526529
with_ui: Whether to deploy with UI.
527530
verbosity: The verbosity level of the CLI.
528531
adk_version: The ADK version to use in Cloud Run.
@@ -580,6 +583,7 @@ def to_cloud_run(
580583
use_local_storage,
581584
),
582585
trace_to_cloud_option='--trace_to_cloud' if trace_to_cloud else '',
586+
otel_to_cloud_option='--otel_to_cloud' if otel_to_cloud else '',
583587
allow_origins_option=allow_origins_option,
584588
adk_version=adk_version,
585589
host_option=host_option,
@@ -956,6 +960,7 @@ def to_gke(
956960
temp_folder: str,
957961
port: int,
958962
trace_to_cloud: bool,
963+
otel_to_cloud: bool,
959964
with_ui: bool,
960965
log_level: str,
961966
adk_version: str,
@@ -981,6 +986,8 @@ def to_gke(
981986
Dockerfile and deployment.yaml.
982987
port: The port of the ADK api server.
983988
trace_to_cloud: Whether to enable Cloud Trace.
989+
otel_to_cloud: Whether to enable exporting OpenTelemetry signals
990+
to Google Cloud.
984991
with_ui: Whether to deploy with UI.
985992
log_level: The logging level.
986993
adk_version: The ADK version to use in GKE.
@@ -1051,6 +1058,7 @@ def to_gke(
10511058
use_local_storage,
10521059
),
10531060
trace_to_cloud_option='--trace_to_cloud' if trace_to_cloud else '',
1061+
otel_to_cloud_option='--otel_to_cloud' if otel_to_cloud else '',
10541062
allow_origins_option=allow_origins_option,
10551063
adk_version=adk_version,
10561064
host_option=host_option,

src/google/adk/cli/cli_tools_click.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,13 @@ def cli_api_server(
13701370
default=False,
13711371
help="Optional. Whether to enable Cloud Trace for cloud run.",
13721372
)
1373+
@click.option(
1374+
"--otel_to_cloud",
1375+
is_flag=True,
1376+
show_default=True,
1377+
default=False,
1378+
help="Optional. Whether to enable OpenTelemetry for Agent Engine.",
1379+
)
13731380
@click.option(
13741381
"--with_ui",
13751382
is_flag=True,
@@ -1450,6 +1457,7 @@ def cli_deploy_cloud_run(
14501457
temp_folder: str,
14511458
port: int,
14521459
trace_to_cloud: bool,
1460+
otel_to_cloud: bool,
14531461
with_ui: bool,
14541462
adk_version: str,
14551463
log_level: str,
@@ -1528,6 +1536,7 @@ def cli_deploy_cloud_run(
15281536
temp_folder=temp_folder,
15291537
port=port,
15301538
trace_to_cloud=trace_to_cloud,
1539+
otel_to_cloud=otel_to_cloud,
15311540
allow_origins=allow_origins,
15321541
with_ui=with_ui,
15331542
log_level=log_level,
@@ -1799,6 +1808,13 @@ def cli_deploy_agent_engine(
17991808
default=False,
18001809
help="Optional. Whether to enable Cloud Trace for GKE.",
18011810
)
1811+
@click.option(
1812+
"--otel_to_cloud",
1813+
is_flag=True,
1814+
show_default=True,
1815+
default=False,
1816+
help="Optional. Whether to enable OpenTelemetry for GKE.",
1817+
)
18021818
@click.option(
18031819
"--with_ui",
18041820
is_flag=True,
@@ -1855,6 +1871,7 @@ def cli_deploy_gke(
18551871
temp_folder: str,
18561872
port: int,
18571873
trace_to_cloud: bool,
1874+
otel_to_cloud: bool,
18581875
with_ui: bool,
18591876
adk_version: str,
18601877
log_level: Optional[str] = None,
@@ -1884,6 +1901,7 @@ def cli_deploy_gke(
18841901
temp_folder=temp_folder,
18851902
port=port,
18861903
trace_to_cloud=trace_to_cloud,
1904+
otel_to_cloud=otel_to_cloud,
18871905
with_ui=with_ui,
18881906
log_level=log_level,
18891907
adk_version=adk_version,

tests/unittests/cli/utils/test_cli_deploy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def mock_subprocess_run(*args, **kwargs):
262262
temp_folder=str(tmp_path),
263263
port=9090,
264264
trace_to_cloud=False,
265+
otel_to_cloud=False,
265266
with_ui=True,
266267
log_level="debug",
267268
adk_version="1.2.0",

tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def test_to_cloud_run_happy_path(
122122
temp_folder=str(tmp_path),
123123
port=8080,
124124
trace_to_cloud=True,
125+
otel_to_cloud=True,
125126
with_ui=with_ui,
126127
log_level="info",
127128
verbosity="info",
@@ -154,6 +155,7 @@ def test_to_cloud_run_happy_path(
154155
assert "ENV GOOGLE_CLOUD_LOCATION=asia-northeast1" in dockerfile_content
155156
assert "RUN pip install google-adk==1.3.0" in dockerfile_content
156157
assert "--trace_to_cloud" in dockerfile_content
158+
assert "--otel_to_cloud" in dockerfile_content
157159

158160
# Check agent dependencies installation based on include_requirements
159161
if include_requirements:
@@ -220,6 +222,7 @@ def _fake_rmtree(path: str | Path, *_a: Any, **_k: Any) -> None:
220222
temp_folder=str(tmp_dir),
221223
port=8080,
222224
trace_to_cloud=False,
225+
otel_to_cloud=False,
223226
with_ui=False,
224227
log_level="info",
225228
verbosity="info",
@@ -258,6 +261,7 @@ def test_to_cloud_run_cleans_temp_dir_on_failure(
258261
temp_folder=str(tmp_dir),
259262
port=8080,
260263
trace_to_cloud=False,
264+
otel_to_cloud=False,
261265
with_ui=False,
262266
log_level="info",
263267
verbosity="info",
@@ -326,6 +330,7 @@ def test_cloud_run_label_merging(
326330
temp_folder=str(tmp_path),
327331
port=8080,
328332
trace_to_cloud=False,
333+
otel_to_cloud=False,
329334
with_ui=False,
330335
log_level="info",
331336
verbosity="info",

0 commit comments

Comments
 (0)