Commit 1ecab47
feat: Updating the Tracing implementation and updating BaseAgent.runLive
This update should make the java tracing consistent with Python ADK:
1. **`BaseAgent.java`**:
* The `runAsync` and `runLive` methods have been modified to create the `InvocationContext` before starting the tracing span.
* The span name for agent invocations has been changed from `"agent_run [<agent name>]"` to `"invoke_agent <agent name>"`.
* A new `Tracing.traceAgentInvocation` method is now called to add initial tracing attributes for the agent invocation.
* In `runLive`, the `runLiveImpl` execution is now wrapped with calls to `beforeAgentCallback` and `afterAgentCallback` to ensure proper tracing of these lifecycle events.
2. **`Tracing.java`**:
* The OpenTelemetry tracer name has been updated from `"com.google.adk"` to `"gcp.vertex.agent"`.
* A new `traceAgentInvocation` method has been added to set standard attributes for agent invocation spans, including `gen_ai.operation.name`, `gen_ai.agent.description`, `gen_ai.agent.name`, and `gen_ai.conversation.id`.
* Attribute keys used in `traceToolCall`, `traceToolResponse`, `traceCallLlm`, and `traceSendData` have been updated to use the `"gcp.vertex.agent."` prefix instead of `"adk."` or `"com.google.adk"`.
* The serialization of message content (like tool call arguments, tool responses, and data) is now guarded by the `CAPTURE_MESSAGE_CONTENT_IN_SPANS` flag. When disabled, empty JSON objects are recorded instead.
* `traceToolResponse` now includes logic to extract and trace the `tool_call.id` and the tool response content from `FunctionResponse` objects.
* `traceCallLlm` now captures additional LLM request and response details, such as `gen_ai.request.top_p`, `gen_ai.request.max_tokens`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.response.finish_reasons`.
PiperOrigin-RevId: 8678886901 parent ee459b3 commit 1ecab47
File tree
6 files changed
+744
-154
lines changed- core/src
- main/java/com/google/adk
- agents
- flows/llmflows
- telemetry
- test/java/com/google/adk
- agents
- telemetry
- testing
6 files changed
+744
-154
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
307 | 308 | | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
| 309 | + | |
| 310 | + | |
312 | 311 | | |
313 | 312 | | |
314 | | - | |
315 | | - | |
316 | 313 | | |
317 | 314 | | |
318 | 315 | | |
| |||
443 | 440 | | |
444 | 441 | | |
445 | 442 | | |
| 443 | + | |
446 | 444 | | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
| 445 | + | |
| 446 | + | |
451 | 447 | | |
452 | 448 | | |
453 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
454 | 475 | | |
455 | | - | |
| 476 | + | |
| 477 | + | |
456 | 478 | | |
457 | 479 | | |
458 | 480 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| |||
571 | 571 | | |
572 | 572 | | |
573 | 573 | | |
574 | | - | |
| 574 | + | |
| 575 | + | |
575 | 576 | | |
576 | 577 | | |
577 | 578 | | |
| |||
620 | 621 | | |
621 | 622 | | |
622 | 623 | | |
623 | | - | |
| 624 | + | |
624 | 625 | | |
625 | 626 | | |
626 | 627 | | |
| |||
0 commit comments