← Back to Pull requests

feat(claude-agent-sdk): emit invoke_agent spans for query() #1060

Open
unknown opened this pull request with 203 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 08, 2026 20:27 UTC
Author

Part of #1059 and #141. _instrument() was a placeholder; this adds query() for a single turn.

Each turn produces one invoke_agent claude-agent-sdk span. The SDK session id becomes gen_ai.conversation.id and overrides an inherited ambient id. Usage comes from ResultMessage only, 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_response parts. Sub-agent spans are not separated yet; OpenInference nests them under the tool span that spawned them via parent_tool_use_id, and the SDK carries that field, so a later PR can do the same.

Type of change

  • New feature (non-breaking)
  • 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

  • Style guidelines

  • Changelog: fragment included

  • Unit tests added

  • Docs: none needed, no docs page
  • Diff: 203 lines (+152 / -51) across 2 files Reviewer: simin-yuan Review duration: 22688m
    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
    0.41
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 41.3% (MEDIUM) · Higher = larger blast radius
    41.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22% · Safe to merge
    22%