perf(telemetry): skip non-recording LLM trace work#6371
Draft
dexhunter wants to merge 1 commit into
Draft
Conversation
Avoid telemetry configuration and payload serialization when the active span cannot record attributes. Refs google#4233
c6b6d96 to
4da52ff
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
trace_call_llmbuilds telemetry configuration and serializes request and response content before writing span attributes, even when the supplied or current span is not recording. A non-recording span cannot retain those values, so large LLM payloads incur avoidable CPU work.Solution:
Resolve the span first and return when
span.is_recording()is false. Recording spans keep the existing telemetry and attribute path unchanged. The regression test covers both explicitly supplied and current spans and proves that neither request nor response serialization runs on the non-recording path.This addresses one narrow source of the repeated serialization reported in #4233; it does not claim to eliminate every serialization path in that issue.
Performance
The strict same-workload evaluator enables content capture and uses a large deterministic response. Each reported run is itself the median of nine benchmark batches.
mainThat is a 99.92% reduction in this helper's non-recording-span overhead. This is a helper-level CPU benchmark, not an end-to-end agent or model latency claim. The evaluator also verifies that recording-span attributes and serialization behavior remain unchanged.
The early-guard direction was identified through autoresearch with Weco. The comparable baseline, patch, and hardened regression are recorded in this public autoresearch trajectory.
Testing Plan
Unit Tests:
Results on the final rebased patch:
pytest tests/unittests/telemetry/test_spans.py -q: 80 passed, 1 skippeduvx ruff check --fix src/google/adk/telemetry/tracing.py tests/unittests/telemetry/test_spans.py: passedgit diff --check: passedManual End-to-End (E2E) Tests:
Not applicable for this tracing guard. The focused unit suite and strict evaluator exercise explicit and current spans, recording and non-recording behavior, request and response serialization, telemetry-disabled cases, tools/no-tools cases, and serialization fallback behavior without an external model request.
Checklist
Additional context
This remains a draft while awaiting maintainer confirmation that the narrow optimization is in scope under the contribution policy.