Skip to content

Commit 2e50b5a

Browse files
authored
Add region tags & cleanup ADK Sample (#421)
* Add region tags & cleanup sample * Remove manual tracing of tool calls * Add region tags in main.py
1 parent 454662b commit 2e50b5a

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

samples/adk-sql-agent/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import logging
1615
import google.auth
1716
import google.auth.transport.requests
1817
import grpc
@@ -97,19 +96,20 @@ def setup_opentelemetry() -> None:
9796

9897
# Load instrumentors
9998
SQLite3Instrumentor().instrument()
99+
# ADK uses Vertex AI and Google Gen AI SDKs.
100100
VertexAIInstrumentor().instrument()
101101
GoogleGenAiSdkInstrumentor().instrument()
102102

103103

104104
# [END opentelemetry_adk_otel_setup]
105105

106-
106+
# [START opentelemetry_adk_launch_web_interface]
107107
def main() -> None:
108108
# Make sure to set:
109109
# OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
110110
# OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
111111
# in order to full prompts and responses and logs messages.
112-
# For this sample, these can be set by loading the `main.env` file.
112+
# For this sample, these can be set by loading the `opentelemetry.env` file.
113113
setup_opentelemetry()
114114

115115
# Call the function to get the FastAPI app instance.
@@ -125,7 +125,9 @@ def main() -> None:
125125
web=SERVE_WEB_INTERFACE,
126126
)
127127

128+
# Lauch the web interface on port 8080.
128129
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
130+
# [END opentelemetry_adk_launch_web_interface]
129131

130132

131133
if __name__ == "__main__":

samples/adk-sql-agent/sql_agent/agent.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
import sqlite3
1919

20-
from opentelemetry import trace
21-
22-
# from utils import ask_prompt, console, print_markdown, render_messages
23-
24-
2520
SYSTEM_PROMPT = f"""\
2621
You are a helpful AI assistant with a mastery of database design and querying. You have access
2722
to an ephemeral sqlite3 database that you can query and modify through some tools. Help answer

samples/adk-sql-agent/sql_agent/tools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class SqlRunResult(TypedDict):
3333
rows: NotRequired[list[tuple[str, ...]]]
3434
"""The rows returned by the SQL query"""
3535

36-
@tracer.start_as_current_span("create_database")
3736
def create_database_tool(tool_context: ToolContext) -> dict[str, Any]:
3837
"""Creates a temporary file in the /tmp directory to hold an ephemeral
3938
sqlite3 database if a database is not found for the current session.
@@ -47,7 +46,6 @@ def create_database_tool(tool_context: ToolContext) -> dict[str, Any]:
4746
return {"resp": "Created an ephemeral database"}
4847
return {"resp": f"Skipping database creation, {tool_context.state[SESSION_DB_KEY]} already exists"}
4948

50-
@tracer.start_as_current_span("run_sql")
5149
def run_sql_tool(sql_query: str, tool_context: ToolContext) -> dict[str, Any]:
5250
"""Runs a SQLite query. The SQL query can be DDL or DML. Returns the rows if it's a SELECT query."""
5351
current_session_db_path = tool_context.state.get(SESSION_DB_KEY)

0 commit comments

Comments
 (0)