feat(claude-agent-sdk): emit invoke_agent spans for query() #1060
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.41) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.41 · 203 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.318
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1060"
general
weight: 0.35
simin-yuan
Part of #1059 and #141.
_instrument()was a placeholder; this addsquery()for a single turn.Each turn produces one
invoke_agent claude-agent-sdkspan. The SDK session id becomesgen_ai.conversation.idand overrides an inherited ambient id. Usage comes fromResultMessageonly, and cache traffic counts into input tokens. SDK-reported error text stays off the span. The stream follows the shared wrapper pattern, so the span starts at the call site. When the CLI's built-in tracing is enabled for the call (CLAUDE_CODE_ENABLE_TELEMETRY=1,CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1, and an exporter), the instrumentation reports nothing, to avoid duplicate spans.The minimum is 0.1.19 because the 0.1.14-0.1.17 releases do not exist on PyPI (the 0.1.x line jumps from 0.1.8 to 0.1.18) and 0.1.18 is yanked.
Built-in tools run inside the Claude Code CLI process, so they are not reported here; their messages still appear as
tool_call/tool_call_responseparts. Sub-agent spans are not separated yet; OpenInference nests them under the tool span that spawned them viaparent_tool_use_id, and the SDK carries that field, so a later PR can do the same.Type of change
How has this been tested?
Locally: 45 tests pass on 0.2.182 and 35 on 0.1.19, the rest skipped by version or environment; ruff clean, pyright strict clean, and the Weaver conformance scenario replays a turn through the shared fake transport and passes live-check.
Checklist