Feat/add instrumentation around async create method#96
Open
eternalcuriouslearner wants to merge 8 commits into
Open
Conversation
Add tracing around AsyncMessages.create, including async streaming responses,and cover the async path with VCR-backed tests. Assisted-by: ChatGPT 5.5
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds async support for Anthropic Messages.create instrumentation and introduces a comprehensive async test suite (including streaming) backed by VCR cassettes.
Changes:
- Instrument
anthropic.resources.messages.AsyncMessages.createand wrap async streaming results. - Add extensive async tests covering content capture modes, streaming behaviors, and error propagation.
- Record VCR cassettes for async scenarios (basic, streaming, cache tokens, tools/thinking, errors).
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_async_messages.py | New async test suite covering create/streaming behaviors and span/log assertions |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conftest.py | Adds AsyncAnthropic fixture for async tests |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_stream_wrapper_finalize_idempotent.yaml | VCR recording for async stream finalization/idempotency |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_with_all_params.yaml | VCR recording for async create with optional params |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_token_usage.yaml | VCR recording for async token usage assertions |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_streaming_user_exception.yaml | VCR recording for user exception during async streaming |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_streaming_iteration.yaml | VCR recording for direct async iteration over stream |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_streaming_delegates_response_attribute.yaml | VCR recording validating response attribute delegation |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_streaming_captures_content.yaml | VCR recording for content capture in async streaming |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_streaming_aggregates_cache_tokens.yaml | VCR recording for cache token aggregation in async streaming |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_streaming.yaml | VCR recording for basic async streaming path |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_stream_propagation_error.yaml | VCR recording for mid-stream error propagation |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_stop_reason.yaml | VCR recording validating stop_reason → finish_reasons mapping |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_event_only_no_content_in_span.yaml | VCR recording for EVENT_ONLY mode emitting log event |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_captures_tool_use_content.yaml | VCR recording for tool_use content extraction |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_captures_thinking_content.yaml | VCR recording for thinking/reasoning content extraction |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_captures_content.yaml | VCR recording for non-streaming content capture |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_basic.yaml | VCR recording for basic async create span assertions |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_api_error.yaml | VCR recording for async API error (404) |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_messages_create_aggregates_cache_tokens.yaml | VCR recording for cache token aggregation in non-streaming async |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/patch.py | Adds async wrapper for AsyncMessages.create and broadens invocation to async/sync |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/messages_extractors.py | Allows extractors to accept AsyncMessages instances |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/init.py | Hooks/unhooks async create instrumentation |
lmolkova
approved these changes
May 27, 2026
lzchen
reviewed
Jun 4, 2026
| return parsed | ||
|
|
||
|
|
||
| def _skip_if_cassette_missing_and_no_real_key(request): |
Contributor
There was a problem hiding this comment.
Doesn't this start a bad precedence of skipping tests if there is no cassette for it?
Contributor
Author
There was a problem hiding this comment.
I added this to avoid build failures if folks don't have an api key and push code without cassettes. Should I remove it?
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.
Description
Adds instrumentation around anthropic async create method.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How has this been tested?
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. List any relevant details for your test
configuration.
Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.