Skip to content

fix(anthropic): instrument AnthropicBedrock beta messages create#18122

Open
joaquinhuigomez wants to merge 1 commit into
DataDog:mainfrom
joaquinhuigomez:fix/anthropic-bedrock-beta-messages
Open

fix(anthropic): instrument AnthropicBedrock beta messages create#18122
joaquinhuigomez wants to merge 1 commit into
DataDog:mainfrom
joaquinhuigomez:fix/anthropic-bedrock-beta-messages

Conversation

@joaquinhuigomez

Copy link
Copy Markdown

anthropic.lib.bedrock._beta_messages defines its own Messages / AsyncMessages classes whose create attribute is bound to the first-party function at module import time — before the post-import hook fires and patch() runs. Wrapping the first-party class never reaches those captured references, so AnthropicBedrock().beta.messages.create(...) produces no span in APM or LLM Observability.

Wrap the Bedrock module paths directly (guarded by an ImportError check for SDK versions that don't ship the module) and mirror in unpatch(). Adds a release note.

Fixes #18075

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
@joaquinhuigomez joaquinhuigomez requested review from a team as code owners May 16, 2026 20:32
@avara1986 avara1986 requested review from Kyle-Verhoog and Yun-Kim May 21, 2026 07:34

@emmettbutler emmettbutler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'll suggest that this is a feature rather than a fix

@datadog-prod-us1-5

Copy link
Copy Markdown
Contributor

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

System Tests | download-s3-wheels   View in Datadog   GitHub Actions

See error Timeout while waiting for resource at 'https://dd-trace-py-builds.s3.amazonaws.com/25c4ac6d0cab7eff2f4a4d410d51b8881813a9e9/index-manylinux2014_x86_64.html'.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 25c4ac6 | Docs | Datadog PR Page | Give us feedback!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Anthropic integration does not instrument AsyncAnthropicBedrock.beta.messages.create — LLM Observability misses Bedrock calls

3 participants