Repository navigation
[opentelemetry-instrumentation-genai-anthropic] Instrument beta.messages create, stream, and parse (#550) - #781
benkawecki wants to merge 10 commits into
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-10-17 01:44 UTC Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):
Status above doesn't look right?
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Redact exposed workspace identifiers and correct the beta raw-response coverage and duplicate conformance registration.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 5
Open (6)
Redact anthropic-workspace-id from cassette · New Redact anthropic-workspace-id from cassette · New Redact anthropic-workspace-id from cassette · New Redact anthropic-workspace-id from cassette · New Use beta resource for beta raw-response streaming test · New Remove duplicate InferenceBetaStreamingScenario entry · New
What changed in this PR
Adds instrumentation for Anthropic beta Messages APIs, including synchronous/asynchronous create, stream, parse, raw responses, and content extraction.
Changes:
- Adds beta-aware wrappers, parsing, streaming, and telemetry extraction.
- Adds unit, conformance, and cassette-backed tests.
- Updates documentation and changelog.
| File | Summary |
|---|---|
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_sync_messages.py |
Tests synchronous beta messages. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_parse_messages.py |
Tests beta parse behavior. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_messages_extractors.py |
Tests beta content extraction. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_instrumentor.py |
Tests instrumentation lifecycle. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_conformance.py |
Registers conformance scenarios. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_async_wrappers.py |
Tests asynchronous stream handling. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_async_messages.py |
Tests asynchronous beta messages. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conformance/tool_calling_beta.py |
Adds beta tool-calling coverage. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conformance/inference_streaming_beta.py |
Adds beta streaming coverage. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conformance/inference_raw_response_beta.py |
Adds beta raw-response coverage. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conformance/inference_beta.py |
Adds beta inference coverage. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conformance/inference_beta_server_tool_calling.py |
Adds beta server tool-calling coverage. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/tool_calling_beta_conformance.yaml |
Records beta tool-calling interactions. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_messages_beta_create_with_raw_response.yaml |
Records synchronous beta raw responses. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_messages_beta_create_streaming.yaml |
Records synchronous beta streaming. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_messages_beta_create_streaming_with_raw_response.yaml |
Records synchronous beta raw streaming. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_beta_messages_with_raw_response.yaml |
Records synchronous beta raw responses. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_beta_messages_stream.yaml |
Records synchronous beta streams. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_beta_messages_parse_basic.yaml |
Records synchronous beta parsing. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_beta_messages_create_with_content.yaml |
Records beta content creation. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_beta_messages_create_streaming.yaml |
Records synchronous beta streaming. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_beta_messages_create_basic.yaml |
Records basic synchronous beta creation. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_sync_beta_messages_create_api_error.yaml |
Records synchronous beta API errors. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_beta_messages_with_raw_response.yaml |
Records asynchronous beta raw responses. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_beta_messages_stream.yaml |
Records asynchronous beta streams. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_beta_messages_parse_basic.yaml |
Records asynchronous beta parsing. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_beta_messages_create_with_content.yaml |
Records asynchronous beta content creation. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_beta_messages_create_streaming.yaml |
Records asynchronous beta streaming. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_beta_messages_create_basic.yaml |
Records basic asynchronous beta creation. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/test_async_beta_messages_create_api_error.yaml |
Records asynchronous beta API errors. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/inference_beta_streaming_conformance.yaml |
Records beta streaming conformance. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/inference_beta_server_tool_calling_conformance.yaml |
Records beta server tool-calling conformance. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/cassettes/inference_beta_conformance.yaml |
Records beta inference conformance. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/wrappers.py |
Handles beta stream accumulation. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/utils.py |
Converts beta content blocks. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/patch.py |
Instruments beta calls and streams. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/messages_extractors.py |
Extracts beta request and response data. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/_raw_response.py |
Supports beta raw responses. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/__init__.py |
Registers beta instrumentation. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/README.rst |
Documents beta API support. |
instrumentation/opentelemetry-instrumentation-genai-anthropic/.changelog/661.added |
Adds the feature changelog entry. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
A couple notes / questions for maintainers.
|
1693211 to
a9c1ce3
Compare
She's OOO but I don't think it's a problem. Can you add her email as a coauthor on https://docs.github.com/en/pull-requests/how-tos/commit-changes/creating-a-commit-with-multiple-authors?
If it's a consistent failure, sending a separate PR would be awesome :)
My 2c, that would be great but consider doing in a separate PR. Thanks! |
…sages create, stream, and parse Adds the beta.messages instrumentation (create/stream/parse spans, raw-response support, server-tool-calling and MCP content classification, conformance scenarios) Co-authored-by: Liudmila Molkova <neskazu@gmail.com> Assisted-by: Claude Sonnet 5
…se and tool-calling conformance scenarios Adds InferenceBetaRawResponseScenario, InferenceBetaRawResponseStreamingScenario, and ToolCallingBetaScenario, closing the beta.messages coverage gap against the existing non-beta conformance scenarios. InferenceBetaStreamingScenario moves out of inference_beta.py into its own inference_streaming_beta.py, matching the inference.py/inference_streaming.py split already used for the non-beta scenarios
d7f4340 to
db81210
Compare
|
@benkawecki Sorry for the delay, looking into this. |
This comment has been minimized.
This comment has been minimized.
Thanks! lmk when you get a chance to take a look. |
|
looking forward to this one 🙏 |
|
@benkawecki could you please resolve conflicts and it should be good to go |
|
@lmolkova conflicts resolved. |
|
@benkawecki sorry, some conflicts again 😞 |
|
@benkawecki could you please fix tests? there were some changes on main wrt capturing lists and some methods were removed. see #873 for the details |
| args: tuple[Any, ...], | ||
| kwargs: dict[str, Any], | ||
| ) -> MessagesStreamManagerWrapper[Any]: | ||
| _materialize_tools(kwargs) |
There was a problem hiding this comment.
why? are these not applicable here? can't input / output messages be iterators / generators here that we consume prematurely?
There was a problem hiding this comment.
I missed this when I did my merge. Removed it as it loos like #873 moved to a different pattern. Let me know if my interpretation of that was not correct.
|
@lmolkova fixed CI issues. |
|
@benkawecki are we capturing compaction span attribute here? |
I don't think so. I see you have a PR to add compaction attributes. Maybe we should add compaction as a separate follow-on PR to this one? |


Description
Fixes 550
This work builds from PR 661
Instruments
anthropic.resources.beta.messages.MessagesandAsyncMessages(create, stream, and parse), including raw and streaming response helpers.Anthropic beta messages provide access to new API features (such as prompt caching, computer use, and MCP tools) while producing standard chat inference spans and metrics.
Type of change
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.
uv run tox -e py312-test-instrumentation-genai-anthropic-conformanceuv run tox -e py312-test-instrumentation-genai-anthropic-latestuv run tox -e py312-test-instrumentation-genai-anthropic-oldestChecklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.