Skip to content

Feat/add instrumentation around async create method#96

Open
eternalcuriouslearner wants to merge 8 commits into
open-telemetry:mainfrom
eternalcuriouslearner:feat/add-instrumentation-around-async-create-method
Open

Feat/add instrumentation around async create method#96
eternalcuriouslearner wants to merge 8 commits into
open-telemetry:mainfrom
eternalcuriouslearner:feat/add-instrumentation-around-async-create-method

Conversation

@eternalcuriouslearner
Copy link
Copy Markdown
Contributor

Description

Adds instrumentation around anthropic async create method.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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.

  • Added new test suite to similar to messages.create method similar to sync api.

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Add tracing around AsyncMessages.create, including async streaming responses,and cover the async path with VCR-backed tests.

Assisted-by: ChatGPT 5.5
Copilot AI review requested due to automatic review settings May 27, 2026 01:49
@eternalcuriouslearner eternalcuriouslearner requested a review from a team as a code owner May 27, 2026 01:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.create and 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

Comment thread instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conftest.py Outdated
Comment thread instrumentation/opentelemetry-instrumentation-genai-anthropic/.changelog/60.fixed Outdated
return parsed


def _skip_if_cassette_missing_and_no_real_key(request):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this start a bad precedence of skipping tests if there is no cassette for it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to avoid build failures if folks don't have an api key and push code without cassettes. Should I remove it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants