fix(agentscope): start streaming LLM spans before model calls#242
Conversation
ralf0131
left a comment
There was a problem hiding this comment.
Summary
This PR fixes two issues in the AgentScope v2 instrumentation:
-
Streaming LLM span lifecycle — The span is now always started before the model handler runs (via
handler.start_llm), instead of deferring it to first-token time for streaming models. This ensures TTFT and the full stream lifecycle are captured on the framework LLM span. Thestartedflag and all its conditional branches are correctly removed, simplifying the control flow. -
String content guard —
_blocks_to_partsnow handlesNone(returns[]) and barestr(wraps inText), so LLM input/output message attributes are populated when AgentScope passes string content instead of block objects.
Tests are solid: test_v2_streaming_model_call_starts_llm_span_before_model_handler verifies the span is active during the model handler, and test_v2_streaming_model_call_captures_input_and_output_content verifies content capture end-to-end.
LGTM — clean simplification, good test coverage, CI green.
Automated review by github-manager-bot
Description
This PR fixes AgentScope v2 streaming model-call telemetry so the framework LLM span starts before the underlying model handler is invoked. This keeps the util-genai context active during the provider call, which prevents duplicate provider LLM spans in full-agent installations while preserving TTFT, token usage, stream finalization, and captured input/output messages on the framework span.
Fixes # (N/A)
Type of change
How Has This Been Tested?
tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-agentscope-latesttox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-agentscope-oldesttox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agentscopePRE_COMMIT_HOME="$(mktemp -d)" tox -e precommitgit diff --checkloongsuite-genaiadvice profileValidation Evidence
Spec and Scope
loongsuite-instrumentation-agentscopev2 middleware, tests, and package changelog.Local Checks
PRE_COMMIT_HOME="$(mktemp -d)" tox -e precommittox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-agentscope-latesttox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-agentscope-oldesttox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agentscopeReal E2E Matrix
py312-test-loongsuite-instrumentation-agentscope-latestpy312-test-loongsuite-instrumentation-agentscope-latest; downstream full-agent live smokepy312-test-loongsuite-instrumentation-agentscope-latestpy312-test-loongsuite-instrumentation-agentscope-latestpy312-test-loongsuite-instrumentation-agentscope-latestpy312-test-loongsuite-instrumentation-agentscope-latestTelemetry and Weaver
py312-test-loongsuite-instrumentation-agentscope-latestgen_ai.input.messagesandgen_ai.output.messagesin SPAN_ONLY mode; NO_CONTENT behavior is unchanged by this diff.py312-test-loongsuite-instrumentation-agentscope-latestweaver registry live-check -r <loongsuite-semantic-conventions>/model --input-source <generated AgentScope v2 streaming JSON sample> --input-format json --advice-profile loongsuite-genai --skip-policies trueCI
Does This PR Require a Core Repo Change?
Checklist: