Skip to content

Commit 7de9eff

Browse files
committed
docs: Revise README for Google ADK instrumentation
Change-Id: If5dbb7ad8f67a9e51ff95398b79f59982020bf5a Co-developed-by: Cursor <[email protected]>
1 parent 649dc9b commit 7de9eff

File tree

1 file changed

+134
-41
lines changed
  • instrumentation-loongsuite/loongsuite-instrumentation-google-adk

1 file changed

+134
-41
lines changed

instrumentation-loongsuite/loongsuite-instrumentation-google-adk/README.md

Lines changed: 134 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,125 @@
11
# OpenTelemetry Google ADK Instrumentation
22

3-
Google ADK (Agent Development Kit) Python Agent provides observability for Google ADK applications.
4-
This document provides examples of usage and results in the Google ADK instrumentation.
5-
For details on usage and installation of LoongSuite and Jaeger, please refer to [LoongSuite Documentation](https://github.com/alibaba/loongsuite-python-agent/blob/main/README.md).
3+
[![OpenTelemetry](https://img.shields.io/badge/OpenTelemetry-GenAI_Semantic_Conventions-blue)](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/)
4+
5+
Google ADK (Agent Development Kit) Python Agent provides comprehensive observability for Google ADK applications using OpenTelemetry.
6+
7+
## Features
8+
9+
-**Automatic Instrumentation**: Zero-code integration via `opentelemetry-instrument`
10+
-**Manual Instrumentation**: Programmatic control via `GoogleAdkInstrumentor`
11+
-**GenAI Semantic Conventions**: Full compliance with OpenTelemetry GenAI standards
12+
-**Comprehensive Spans**: `invoke_agent`, `chat`, `execute_tool`
13+
-**Standard Metrics**: Operation duration and token usage
14+
-**Content Capture**: Optional message and response content capture
15+
-**Google ADK native instrumentation Compatible**: Works seamlessly with ADK native instrumentation
16+
17+
## Quick Start
18+
19+
```bash
20+
# Install
21+
pip install google-adk litellm
22+
pip install ./instrumentation-loongsuite/loongsuite-instrumentation-google-adk
23+
24+
# Configure
25+
export DASHSCOPE_API_KEY=your-api-key
26+
27+
# Run with auto instrumentation
28+
opentelemetry-instrument \
29+
--traces_exporter console \
30+
--service_name my-adk-app \
31+
python your_app.py
32+
```
33+
34+
For details on LoongSuite and Jaeger setup, refer to [LoongSuite Documentation](https://github.com/alibaba/loongsuite-python-agent/blob/main/README.md).
635

736
## Installing Google ADK Instrumentation
837

938
```shell
10-
# Open Telemetry
39+
# OpenTelemetry Core
1140
pip install opentelemetry-distro opentelemetry-exporter-otlp
1241
opentelemetry-bootstrap -a install
1342

14-
# google-adk
43+
# Google ADK and LLM Dependencies
1544
pip install google-adk>=0.1.0
1645
pip install litellm
1746

47+
# Demo Application Dependencies (optional, only if running examples)
48+
pip install fastapi uvicorn pydantic
49+
1850
# GoogleAdkInstrumentor
1951
git clone https://github.com/alibaba/loongsuite-python-agent.git
2052
cd loongsuite-python-agent
21-
pip install ./instrumentation-genai/opentelemetry-instrumentation-google-adk
53+
pip install ./instrumentation-loongsuite/loongsuite-instrumentation-google-adk
2254
```
2355

2456
## Collect Data
2557

2658
Here's a simple demonstration of Google ADK instrumentation. The demo uses:
2759

28-
- A [Google ADK application](examples/simple_adk_app.py) that demonstrates agent interactions
60+
- A [Google ADK application](examples/main.py) that demonstrates agent interactions with multiple tools
2961

3062
### Running the Demo
3163

32-
#### Option 1: Using OpenTelemetry
64+
> **Note**: The demo uses DashScope (Alibaba Cloud LLM service) by default. You need to set the `DASHSCOPE_API_KEY` environment variable.
65+
66+
#### Option 1: Using OpenTelemetry Auto Instrumentation
3367

3468
```bash
69+
# Set your DashScope API key
70+
export DASHSCOPE_API_KEY=your-dashscope-api-key
71+
72+
# Enable content capture (optional, for debugging)
3573
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
3674

75+
# Run with auto instrumentation
3776
opentelemetry-instrument \
38-
--traces_exporter console \
39-
--service_name demo-google-adk \
40-
python examples/main.py
77+
--traces_exporter console \
78+
--service_name demo-google-adk \
79+
python examples/main.py
4180
```
4281

4382
#### Option 2: Using Loongsuite
4483

4584
```bash
46-
export DASHSCOPE_API_KEY=xxxx
85+
# Set your DashScope API key
86+
export DASHSCOPE_API_KEY=your-dashscope-api-key
87+
88+
# Enable content capture (optional, for debugging)
4789
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
4890

91+
# Run with loongsuite instrumentation
4992
loongsuite-instrument \
50-
--traces_exporter console \
51-
--service_name demo-google-adk \
52-
python examples/main.py
93+
--traces_exporter console \
94+
--service_name demo-google-adk \
95+
python examples/main.py
5396
```
5497

55-
### Results
98+
#### Option 3: Export to Jaeger
99+
100+
```bash
101+
# Set your DashScope API key
102+
export DASHSCOPE_API_KEY=your-dashscope-api-key
103+
104+
# Configure OTLP exporter
105+
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
106+
export OTEL_TRACES_EXPORTER=otlp
107+
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
108+
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
109+
110+
# Run the application
111+
opentelemetry-instrument \
112+
--service_name demo-google-adk \
113+
python examples/main.py
114+
```
115+
116+
### Expected Results
56117

57118
The instrumentation will generate traces showing the Google ADK operations:
58119

59-
```bash
120+
#### Tool Execution Span Example
121+
122+
```json
60123
{
61124
"name": "execute_tool get_current_time",
62125
"context": {
@@ -73,15 +136,10 @@ The instrumentation will generate traces showing the Google ADK operations:
73136
},
74137
"attributes": {
75138
"gen_ai.operation.name": "execute_tool",
76-
"gen_ai.tool.description": "xxx",
77139
"gen_ai.tool.name": "get_current_time",
78-
"gen_ai.tool.type": "FunctionTool",
79-
"gcp.vertex.agent.llm_request": "{}",
80-
"gcp.vertex.agent.llm_response": "{}",
81-
"gcp.vertex.agent.tool_call_args": "{}",
82-
"gen_ai.tool.call.id": "xxx",
83-
"gcp.vertex.agent.event_id": "xxxx",
84-
"gcp.vertex.agent.tool_response": "xxx"
140+
"gen_ai.tool.description": "xxx",
141+
"input.value": "{xxx}",
142+
"output.value": "{xxx}"
85143
},
86144
"events": [],
87145
"links": [],
@@ -90,30 +148,47 @@ The instrumentation will generate traces showing the Google ADK operations:
90148
"telemetry.sdk.language": "python",
91149
"telemetry.sdk.name": "opentelemetry",
92150
"telemetry.sdk.version": "1.37.0",
93-
"service.name": "demo-google-adk",
94-
"telemetry.auto.version": "0.59b0"
151+
"service.name": "demo-google-adk"
95152
},
96153
"schema_url": ""
97154
}
98155
}
99156
```
100157

101-
After [setting up jaeger](https://www.jaegertracing.io/docs/1.6/getting-started/) and exporting data to it by following these commands:
158+
#### LLM Chat Span Example
102159

103-
```bash
104-
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
105-
106-
loongsuite-instrument \
107-
--exporter_otlp_protocol grpc \
108-
--traces_exporter otlp \
109-
--exporter_otlp_insecure true \
110-
--exporter_otlp_endpoint YOUR-END-POINT \
111-
python examples/main.py
160+
```json
161+
{
162+
"name": "chat qwen-max",
163+
"kind": "SpanKind.CLIENT",
164+
"attributes": {
165+
"gen_ai.operation.name": "chat",
166+
"gen_ai.request.model": "qwen-max",
167+
"gen_ai.response.model": "qwen-max",
168+
"gen_ai.usage.input_tokens": 150,
169+
"gen_ai.usage.output_tokens": 45
170+
}
171+
}
112172
```
113173

114-
You can see traces on the jaeger UI:
174+
#### Agent Invocation Span Example
175+
176+
```json
177+
{
178+
"name": "invoke_agent ToolAgent",
179+
"kind": "SpanKind.CLIENT",
180+
"attributes": {
181+
"gen_ai.operation.name": "invoke_agent",
182+
"gen_ai.agent.name": "ToolAgent",
183+
"input.value": "[{\"role\": \"user\", \"parts\": [{\"type\": \"text\", \"content\": \"现在几点了?\"}]}]",
184+
"output.value": "[{\"role\": \"assistant\", \"parts\": [{\"type\": \"text\", \"content\": \"当前时间是 2025-11-27 14:36:33\"}]}]"
185+
}
186+
}
187+
```
115188

189+
### Viewing in Jaeger
116190

191+
After [setting up Jaeger](https://www.jaegertracing.io/docs/latest/getting-started/), you can visualize the complete trace hierarchy in the Jaeger UI, showing the relationships between Runner, Agent, LLM, and Tool spans
117192

118193
## Configuration
119194

@@ -124,6 +199,7 @@ The following environment variables can be used to configure the Google ADK inst
124199
| Variable | Description | Default |
125200
|----------|-------------|---------|
126201
| `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` | Capture message content in traces | `false` |
202+
| `DASHSCOPE_API_KEY` | DashScope API key (required for demo) | - |
127203

128204
### Programmatic Configuration
129205

@@ -225,11 +301,28 @@ This instrumentation follows the OpenTelemetry GenAI semantic conventions:
225301

226302
### Common Issues
227303

228-
1. **Module Import Error**: If you encounter `No module named 'google.adk.runners'`, ensure that `google-adk` is properly installed.
304+
1. **Module Import Error**: If you encounter `No module named 'google.adk.runners'`, ensure that `google-adk` is properly installed:
305+
```bash
306+
pip install google-adk>=0.1.0
307+
```
308+
309+
2. **DashScope API Error**: If you see authentication errors, verify your API key is correctly set:
310+
```bash
311+
export DASHSCOPE_API_KEY=your-api-key
312+
# Verify it's set
313+
echo $DASHSCOPE_API_KEY
314+
```
315+
316+
3. **Instrumentation Not Working**:
317+
- Check that the instrumentation is enabled and the Google ADK application is using the `Runner` class
318+
- Verify you see the log message: `Plugin 'opentelemetry_adk_observability' registered`
319+
- For manual instrumentation, ensure you call `GoogleAdkInstrumentor().instrument()` before creating the Runner
229320

230-
2. **Instrumentation Not Working**: Check that the instrumentation is enabled and the Google ADK application is using the `Runner` class.
321+
4. **Missing Traces**:
322+
- Verify that the OpenTelemetry exporters are properly configured
323+
- Check the `OTEL_TRACES_EXPORTER` environment variable is set (e.g., `console`, `otlp`)
324+
- For OTLP exporter, ensure the endpoint is reachable
231325

232-
3. **Missing Traces**: Verify that the OpenTelemetry exporters are properly configured.
233326

234327
## References
235328

0 commit comments

Comments
 (0)