Skip to content

Commit c897be3

Browse files
committed
feat: Add Google ADK instrumentation support to Tox and GitHub workflows
- Introduced new Tox environments for testing and linting Google ADK instrumentation across multiple Python versions. - Updated GitHub Actions workflows to include jobs for linting and testing Google ADK instrumentation. - Added requirements files for both latest and oldest dependencies for Google ADK tests. - Enhanced error handling in main.py and improved logging for better debugging. This update enhances the testing framework and ensures comprehensive coverage for Google ADK instrumentation. Change-Id: [insert-change-id-here] Change-Id: I0013d216d47a9dd8146752ffb67d4cd18dfe3679 Co-developed-by: Cursor <[email protected]>
1 parent 661a5da commit c897be3

File tree

12 files changed

+379
-221
lines changed

12 files changed

+379
-221
lines changed

.github/workflows/loongsuite_lint_0.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ jobs:
7070
- name: Run tests
7171
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-dashscope
7272

73+
lint-loongsuite-instrumentation-google-adk:
74+
name: LoongSuite loongsuite-instrumentation-google-adk
75+
runs-on: ubuntu-latest
76+
timeout-minutes: 30
77+
steps:
78+
- name: Checkout repo @ SHA - ${{ github.sha }}
79+
uses: actions/checkout@v4
80+
81+
- name: Set up Python 3.13
82+
uses: actions/setup-python@v5
83+
with:
84+
python-version: "3.13"
85+
86+
- name: Install tox
87+
run: pip install tox-uv
88+
89+
- name: Run tests
90+
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-google-adk
91+
7392
lint-loongsuite-instrumentation-mem0:
7493
name: LoongSuite loongsuite-instrumentation-mem0
7594
runs-on: ubuntu-latest

.github/workflows/loongsuite_test_0.yml

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,196 @@ jobs:
374374
- name: Run tests
375375
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-dashscope-latest -- -ra
376376

377+
py39-test-loongsuite-instrumentation-google-adk-oldest_ubuntu-latest:
378+
name: LoongSuite loongsuite-instrumentation-google-adk-oldest 3.9 Ubuntu
379+
runs-on: ubuntu-latest
380+
timeout-minutes: 30
381+
steps:
382+
- name: Checkout repo @ SHA - ${{ github.sha }}
383+
uses: actions/checkout@v4
384+
385+
- name: Set up Python 3.9
386+
uses: actions/setup-python@v5
387+
with:
388+
python-version: "3.9"
389+
390+
- name: Install tox
391+
run: pip install tox-uv
392+
393+
- name: Run tests
394+
run: tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-google-adk-oldest -- -ra
395+
396+
py39-test-loongsuite-instrumentation-google-adk-latest_ubuntu-latest:
397+
name: LoongSuite loongsuite-instrumentation-google-adk-latest 3.9 Ubuntu
398+
runs-on: ubuntu-latest
399+
timeout-minutes: 30
400+
steps:
401+
- name: Checkout repo @ SHA - ${{ github.sha }}
402+
uses: actions/checkout@v4
403+
404+
- name: Set up Python 3.9
405+
uses: actions/setup-python@v5
406+
with:
407+
python-version: "3.9"
408+
409+
- name: Install tox
410+
run: pip install tox-uv
411+
412+
- name: Run tests
413+
run: tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-google-adk-latest -- -ra
414+
415+
py310-test-loongsuite-instrumentation-google-adk-oldest_ubuntu-latest:
416+
name: LoongSuite loongsuite-instrumentation-google-adk-oldest 3.10 Ubuntu
417+
runs-on: ubuntu-latest
418+
timeout-minutes: 30
419+
steps:
420+
- name: Checkout repo @ SHA - ${{ github.sha }}
421+
uses: actions/checkout@v4
422+
423+
- name: Set up Python 3.10
424+
uses: actions/setup-python@v5
425+
with:
426+
python-version: "3.10"
427+
428+
- name: Install tox
429+
run: pip install tox-uv
430+
431+
- name: Run tests
432+
run: tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-google-adk-oldest -- -ra
433+
434+
py310-test-loongsuite-instrumentation-google-adk-latest_ubuntu-latest:
435+
name: LoongSuite loongsuite-instrumentation-google-adk-latest 3.10 Ubuntu
436+
runs-on: ubuntu-latest
437+
timeout-minutes: 30
438+
steps:
439+
- name: Checkout repo @ SHA - ${{ github.sha }}
440+
uses: actions/checkout@v4
441+
442+
- name: Set up Python 3.10
443+
uses: actions/setup-python@v5
444+
with:
445+
python-version: "3.10"
446+
447+
- name: Install tox
448+
run: pip install tox-uv
449+
450+
- name: Run tests
451+
run: tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-google-adk-latest -- -ra
452+
453+
py311-test-loongsuite-instrumentation-google-adk-oldest_ubuntu-latest:
454+
name: LoongSuite loongsuite-instrumentation-google-adk-oldest 3.11 Ubuntu
455+
runs-on: ubuntu-latest
456+
timeout-minutes: 30
457+
steps:
458+
- name: Checkout repo @ SHA - ${{ github.sha }}
459+
uses: actions/checkout@v4
460+
461+
- name: Set up Python 3.11
462+
uses: actions/setup-python@v5
463+
with:
464+
python-version: "3.11"
465+
466+
- name: Install tox
467+
run: pip install tox-uv
468+
469+
- name: Run tests
470+
run: tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-google-adk-oldest -- -ra
471+
472+
py311-test-loongsuite-instrumentation-google-adk-latest_ubuntu-latest:
473+
name: LoongSuite loongsuite-instrumentation-google-adk-latest 3.11 Ubuntu
474+
runs-on: ubuntu-latest
475+
timeout-minutes: 30
476+
steps:
477+
- name: Checkout repo @ SHA - ${{ github.sha }}
478+
uses: actions/checkout@v4
479+
480+
- name: Set up Python 3.11
481+
uses: actions/setup-python@v5
482+
with:
483+
python-version: "3.11"
484+
485+
- name: Install tox
486+
run: pip install tox-uv
487+
488+
- name: Run tests
489+
run: tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-google-adk-latest -- -ra
490+
491+
py312-test-loongsuite-instrumentation-google-adk-oldest_ubuntu-latest:
492+
name: LoongSuite loongsuite-instrumentation-google-adk-oldest 3.12 Ubuntu
493+
runs-on: ubuntu-latest
494+
timeout-minutes: 30
495+
steps:
496+
- name: Checkout repo @ SHA - ${{ github.sha }}
497+
uses: actions/checkout@v4
498+
499+
- name: Set up Python 3.12
500+
uses: actions/setup-python@v5
501+
with:
502+
python-version: "3.12"
503+
504+
- name: Install tox
505+
run: pip install tox-uv
506+
507+
- name: Run tests
508+
run: tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-google-adk-oldest -- -ra
509+
510+
py312-test-loongsuite-instrumentation-google-adk-latest_ubuntu-latest:
511+
name: LoongSuite loongsuite-instrumentation-google-adk-latest 3.12 Ubuntu
512+
runs-on: ubuntu-latest
513+
timeout-minutes: 30
514+
steps:
515+
- name: Checkout repo @ SHA - ${{ github.sha }}
516+
uses: actions/checkout@v4
517+
518+
- name: Set up Python 3.12
519+
uses: actions/setup-python@v5
520+
with:
521+
python-version: "3.12"
522+
523+
- name: Install tox
524+
run: pip install tox-uv
525+
526+
- name: Run tests
527+
run: tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-google-adk-latest -- -ra
528+
529+
py313-test-loongsuite-instrumentation-google-adk-oldest_ubuntu-latest:
530+
name: LoongSuite loongsuite-instrumentation-google-adk-oldest 3.13 Ubuntu
531+
runs-on: ubuntu-latest
532+
timeout-minutes: 30
533+
steps:
534+
- name: Checkout repo @ SHA - ${{ github.sha }}
535+
uses: actions/checkout@v4
536+
537+
- name: Set up Python 3.13
538+
uses: actions/setup-python@v5
539+
with:
540+
python-version: "3.13"
541+
542+
- name: Install tox
543+
run: pip install tox-uv
544+
545+
- name: Run tests
546+
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-google-adk-oldest -- -ra
547+
548+
py313-test-loongsuite-instrumentation-google-adk-latest_ubuntu-latest:
549+
name: LoongSuite loongsuite-instrumentation-google-adk-latest 3.13 Ubuntu
550+
runs-on: ubuntu-latest
551+
timeout-minutes: 30
552+
steps:
553+
- name: Checkout repo @ SHA - ${{ github.sha }}
554+
uses: actions/checkout@v4
555+
556+
- name: Set up Python 3.13
557+
uses: actions/setup-python@v5
558+
with:
559+
python-version: "3.13"
560+
561+
- name: Install tox
562+
run: pip install tox-uv
563+
564+
- name: Run tests
565+
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-google-adk-latest -- -ra
566+
377567
py310-test-loongsuite-instrumentation-mem0-oldest_ubuntu-latest:
378568
name: LoongSuite loongsuite-instrumentation-mem0-oldest 3.10 Ubuntu
379569
runs-on: ubuntu-latest

instrumentation-loongsuite/loongsuite-instrumentation-google-adk/examples/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import os
1010
import sys
11+
import traceback
1112
from datetime import datetime
1213
from typing import Any, Dict, Optional
1314

@@ -247,8 +248,6 @@ async def run_conversation(
247248

248249
except Exception as e:
249250
logger.error(f"处理消息时出错: {e}")
250-
import traceback
251-
252251
logger.error(f"详细错误信息: {traceback.format_exc()}")
253252
raise HTTPException(status_code=500, detail=f"处理消息失败: {str(e)}")
254253

instrumentation-loongsuite/loongsuite-instrumentation-google-adk/src/opentelemetry/instrumentation/google_adk/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# opentelemetry-instrument python your_app.py
1414
"""
1515

16+
import importlib.util
1617
import logging
1718
from typing import Collection, Optional
1819

@@ -25,6 +26,7 @@
2526
from opentelemetry.semconv.schemas import Schemas
2627

2728
from .internal._plugin import GoogleAdkObservabilityPlugin
29+
from .package import _instruments
2830
from .version import __version__
2931

3032
_logger = logging.getLogger(__name__)
@@ -148,7 +150,7 @@ def instrumentation_dependencies(self) -> Collection[str]:
148150
Returns:
149151
Collection of required packages
150152
"""
151-
return ["google-adk >= 0.1.0"]
153+
return _instruments
152154

153155
def _instrument(self, **kwargs):
154156
"""
@@ -164,8 +166,6 @@ def _instrument(self, **kwargs):
164166
- meter_provider: Custom meter provider
165167
"""
166168
# Check if google-adk is installed
167-
import importlib.util
168-
169169
if importlib.util.find_spec("google.adk.runners") is None:
170170
_logger.warning(
171171
"google-adk not found, instrumentation will not be applied"
@@ -200,7 +200,7 @@ def _uninstrument(self, **kwargs):
200200

201201
try:
202202
# Unwrap the Runner initialization
203-
from google.adk.runners import Runner
203+
from google.adk.runners import Runner # noqa: PLC0415
204204

205205
unwrap(Runner, "__init__")
206206

instrumentation-loongsuite/loongsuite-instrumentation-google-adk/src/opentelemetry/instrumentation/google_adk/internal/_metrics.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ def record_llm_call(
7171
error_type: Optional[str] = None,
7272
prompt_tokens: int = 0,
7373
completion_tokens: int = 0,
74-
conversation_id: Optional[str] = None,
75-
user_id: Optional[str] = None,
7674
) -> None:
7775
"""
7876
Record LLM call metrics following standard OTel GenAI conventions.
@@ -84,8 +82,6 @@ def record_llm_call(
8482
error_type: Error type if error occurred
8583
prompt_tokens: Number of prompt tokens
8684
completion_tokens: Number of completion tokens
87-
conversation_id: Conversation ID (not used in metrics due to high cardinality)
88-
user_id: User ID (not used in metrics due to high cardinality)
8985
"""
9086
try:
9187
# ✅ Build standard attributes for operation.duration
@@ -139,8 +135,6 @@ def record_agent_call(
139135
agent_name: str,
140136
duration: float,
141137
error_type: Optional[str] = None,
142-
conversation_id: Optional[str] = None,
143-
user_id: Optional[str] = None,
144138
) -> None:
145139
"""
146140
Record Agent call metrics following standard OTel GenAI conventions.
@@ -150,8 +144,6 @@ def record_agent_call(
150144
agent_name: Agent name
151145
duration: Duration in seconds
152146
error_type: Error type if error occurred
153-
conversation_id: Conversation ID (not used in metrics due to high cardinality)
154-
user_id: User ID (not used in metrics due to high cardinality)
155147
"""
156148
try:
157149
# ✅ Build standard attributes
@@ -184,8 +176,6 @@ def record_tool_call(
184176
tool_name: str,
185177
duration: float,
186178
error_type: Optional[str] = None,
187-
conversation_id: Optional[str] = None,
188-
user_id: Optional[str] = None,
189179
) -> None:
190180
"""
191181
Record Tool call metrics following standard OTel GenAI conventions.
@@ -195,8 +185,6 @@ def record_tool_call(
195185
tool_name: Tool name
196186
duration: Duration in seconds
197187
error_type: Error type if error occurred
198-
conversation_id: Conversation ID (not used in metrics due to high cardinality)
199-
user_id: User ID (not used in metrics due to high cardinality)
200188
"""
201189
try:
202190
# ✅ Build standard attributes

0 commit comments

Comments
 (0)