Add Claude Agent SDK query instrumentation and tests#2
Open
eternalcuriouslearner wants to merge 1 commit into
Open
Add Claude Agent SDK query instrumentation and tests#2eternalcuriouslearner wants to merge 1 commit into
eternalcuriouslearner wants to merge 1 commit into
Conversation
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
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.
Motivation
claude_agent_sdk.queryto emitinvoke_agentspans and optionally capture message content, as noted in the changelog entry.TelemetryHandlerso the instrumentor delegates tracing/logging/metrics handling consistently with other GenAI instrumentations.Description
patch.pythat wrapsclaude_agent_sdk.query, injects SDK hooks, starts/stops an_QuerySessionusingTelemetryHandler.invoke_local_agent, and returns a_QueryStreamwrapper to manage async iteration and error handling.__init__.pyto construct aTelemetryHandlerand callpatch/unpatchinstead of manually creating tracer/meter/logger instances.tests/test_instrumentor.pyto verify hooks are injected, user hooks are preserved, stream errors are recorded, and instrument/uninstrument behavior works as expected.tests/conformance/query.pyand a VCR cassettetests/cassettes/test_query_real_agent_span.yaml, and updatetox.inito include the conformance env and test commands for the Claude Agent SDK instrumentation.Testing
instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/tests/test_instrumentor.py, and they passed.QueryScenarioviatests/test_conformance.pywith the provided VCR cassette usingpytest, and it passed.Codex Task