refactor: Simplifying the code around tracing#1296
Open
copybara-service[bot] wants to merge 1 commit into
Open
refactor: Simplifying the code around tracing#1296copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
This change simplifies telemetry and tracing logic in the ADK by migrating from manual resource management and helper methods to **RxJava Transformers**.
### Key Changes
* **Introduced Telemetry Transformers**: Created `AgentInvocationTransformer` and `ToolExecutionTransformer` in `Instrumentation.java`. These encapsulate the lifecycle of OpenTelemetry spans and metrics within RxJava's `compose` operator, replacing manual `Flowable.using` blocks in the business logic.
* **Refactored `BaseAgent` and `Functions`**: Updated `BaseAgent.run` and tool execution logic in `Functions.java` to use these new transformers. This results in cleaner, more readable reactive pipelines.
* **Improved Tracing Lifecycle**: Refactored `TracerProvider` in `Tracing.java` to use `Flowable.using` (and equivalents) instead of `doOnSubscribe`/`doFinally`. This ensures that spans and scopes are more reliably closed across various RxJava terminal events.
* **Cleaned up `Instrumentation` API**:
* Removed `recordAgentInvocation` and `recordToolExecution` static helpers in favor of the transformer pattern.
* Added a `makeCurrent()` method to `ClosableTelemetryScope` to allow re-activating scopes within the reactive lifecycle.
* **Removed Unused Code**: Deleted `traceAgent` from `Tracing.java` as it is no longer needed with the new transformer-based approach.
PiperOrigin-RevId: 936674781
bde29ff to
7a4fe74
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: Simplifying the code around tracing
This change simplifies telemetry and tracing logic in the ADK by migrating from manual resource management and helper methods to RxJava Transformers.
Key Changes
AgentInvocationTransformerandToolExecutionTransformerinInstrumentation.java. These encapsulate the lifecycle of OpenTelemetry spans and metrics within RxJava'scomposeoperator, replacing manualFlowable.usingblocks in the business logic.BaseAgentandFunctions: UpdatedBaseAgent.runand tool execution logic inFunctions.javato use these new transformers. This results in cleaner, more readable reactive pipelines.TracerProviderinTracing.javato useFlowable.using(and equivalents) instead ofdoOnSubscribe/doFinally. This ensures that spans and scopes are more reliably closed across various RxJava terminal events.InstrumentationAPI:recordAgentInvocationandrecordToolExecutionstatic helpers in favor of the transformer pattern.makeCurrent()method toClosableTelemetryScopeto allow re-activating scopes within the reactive lifecycle.traceAgentfromTracing.javaas it is no longer needed with the new transformer-based approach.