Skip to content

Add Claude Agent SDK query instrumentation and tests#2

Open
eternalcuriouslearner wants to merge 1 commit into
mainfrom
codex/port-claude-agent-ask-from-issue-141
Open

Add Claude Agent SDK query instrumentation and tests#2
eternalcuriouslearner wants to merge 1 commit into
mainfrom
codex/port-claude-agent-ask-from-issue-141

Conversation

@eternalcuriouslearner

Copy link
Copy Markdown
Owner

Motivation

  • Add instrumentation for claude_agent_sdk.query to emit invoke_agent spans and optionally capture message content, as noted in the changelog entry.
  • Integrate with existing TelemetryHandler so the instrumentor delegates tracing/logging/metrics handling consistently with other GenAI instrumentations.

Description

  • Implement patch.py that wraps claude_agent_sdk.query, injects SDK hooks, starts/stops an _QuerySession using TelemetryHandler.invoke_local_agent, and returns a _QueryStream wrapper to manage async iteration and error handling.
  • Update the instrumentor __init__.py to construct a TelemetryHandler and call patch/unpatch instead of manually creating tracer/meter/logger instances.
  • Add unit tests in tests/test_instrumentor.py to verify hooks are injected, user hooks are preserved, stream errors are recorded, and instrument/uninstrument behavior works as expected.
  • Add a conformance scenario tests/conformance/query.py and a VCR cassette tests/cassettes/test_query_real_agent_span.yaml, and update tox.ini to include the conformance env and test commands for the Claude Agent SDK instrumentation.

Testing

  • Ran unit tests for the instrumentation, including instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/tests/test_instrumentor.py, and they passed.
  • Executed the conformance scenario QueryScenario via tests/test_conformance.py with the provided VCR cassette using pytest, and it passed.
  • Verified that the new patching/unpatching behavior does not break existing instrumentor lifecycle tests, and those tests passed.

Codex Task

Rename the conformance cassette after the donated OpenInference query cassette and synthesize hook control requests in the replay transport instead of storing them in the cassette.

Link: open-telemetry#141
Assisted-by: GPT-5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant