fix(anthropic): instrument AnthropicBedrock beta messages create#18122
Open
joaquinhuigomez wants to merge 1 commit into
Open
fix(anthropic): instrument AnthropicBedrock beta messages create#18122joaquinhuigomez wants to merge 1 commit into
joaquinhuigomez wants to merge 1 commit into
Conversation
The anthropic.lib.bedrock._beta_messages module defines its own Messages and AsyncMessages classes whose 'create' attribute is bound to the first-party function at module import time. That binding is captured before the anthropic post-import hook fires and patch() runs, so wrap() on the first-party class never reaches the Bedrock copies and any call to AnthropicBedrock().beta.messages.create(...) produces no span. Wrap the Bedrock module paths directly (guarded by an ImportError check for SDK versions that don't ship the module) so APM and LLM Observability work the same way for first-party and Bedrock clients. Fixes DataDog#18075
emmettbutler
requested changes
Jun 3, 2026
emmettbutler
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the contribution! Please add a test exercising the new functionality.
| --- | ||
| fixes: | ||
| - | | ||
| anthropic: Fixes missing APM and LLM Observability spans for ``AnthropicBedrock`` / ``AsyncAnthropicBedrock`` clients when calling the beta messages API. |
Collaborator
There was a problem hiding this comment.
I'll suggest that this is a feature rather than a fix
Contributor
|
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.
anthropic.lib.bedrock._beta_messagesdefines its ownMessages/AsyncMessagesclasses whosecreateattribute is bound to the first-party function at module import time — before the post-import hook fires andpatch()runs. Wrapping the first-party class never reaches those captured references, soAnthropicBedrock().beta.messages.create(...)produces no span in APM or LLM Observability.Wrap the Bedrock module paths directly (guarded by an
ImportErrorcheck for SDK versions that don't ship the module) and mirror inunpatch(). Adds a release note.Fixes #18075