Commit 284aff6
refactor: Simplifiying Tracing code
Refactor the tracing implementation within the Google ADK to simplify how OpenTelemetry spans are managed, especially within RxJava streams.
The key changes include:
1. **Introducing `Tracing.TracerProvider`**: A new set of RxJava transformers (`FlowableTransformer`, `SingleTransformer`, `MaybeTransformer`, `CompletableTransformer`) is added in `Tracing.java`. These transformers, created via `Tracing.trace()` methods, handle the lifecycle of OpenTelemetry spans, including span creation, making the span current, and ending the span upon stream completion or error.
2. **Simplifying Tracing Calls**: Instead of manually creating and managing spans with `Tracer`, `Span`, and `Scope`, various parts of the codebase now use the `.compose(Tracing.trace(...))` operator on RxJava streams. This is applied in:
* `BaseAgent.java`: For agent invocations using `Tracing.traceAgent`.
* `BaseLlmFlow.java`: For LLM calls (`call_llm`) and sending data (`send_data`).
* `Functions.java`: For tool responses and tool calls.
* `Runner.java`: For overall invocation spans in `runAsync` and `runLive`.
3. **Centralized Attribute Setting**: Helper methods like `getValidCurrentSpan`, `setInvocationAttributes`, `setToolExecutionAttributes`, and `setJsonAttribute` are added to `Tracing.java` to encapsulate and standardize how attributes are set on spans, including handling JSON serialization and checks for valid spans.
These changes aim to reduce tracing-related boilerplate, improve consistency, and make the tracing logic more robust by tying span lifetimes to RxJava stream lifecycles.
PiperOrigin-RevId: 8697147391 parent bd1b82e commit 284aff6
File tree
6 files changed
+657
-573
lines changed- core/src
- main/java/com/google/adk
- agents
- flows/llmflows
- runner
- telemetry
- test/java/com/google/adk/telemetry
6 files changed
+657
-573
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 32 | | |
36 | 33 | | |
37 | 34 | | |
| |||
315 | 312 | | |
316 | 313 | | |
317 | 314 | | |
318 | | - | |
319 | 315 | | |
320 | 316 | | |
321 | 317 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
356 | 346 | | |
357 | 347 | | |
358 | 348 | | |
| |||
364 | 354 | | |
365 | 355 | | |
366 | 356 | | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
| 357 | + | |
| 358 | + | |
372 | 359 | | |
373 | 360 | | |
374 | 361 | | |
| |||
379 | 366 | | |
380 | 367 | | |
381 | 368 | | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
386 | 378 | | |
387 | 379 | | |
388 | 380 | | |
| |||
523 | 515 | | |
524 | 516 | | |
525 | 517 | | |
526 | | - | |
527 | | - | |
| 518 | + | |
528 | 519 | | |
529 | 520 | | |
530 | 521 | | |
| |||
0 commit comments