Skip to content

Conversation

galkleinman
Copy link
Contributor

@galkleinman galkleinman commented Aug 14, 2025

Important

Disable beta API instrumentation in __init__.py and skip related tests in test_bedrock_with_raw_response.py.

  • Instrumentation:
    • Comment out beta API methods in __init__.py, disabling their instrumentation.
    • Affects both regular Anthropic SDK and Bedrock SDK methods.
  • Testing:
    • Add @pytest.mark.skip to test_async_anthropic_bedrock_with_raw_response, test_async_anthropic_bedrock_regular_create, and test_async_anthropic_bedrock_beta_with_raw_response in test_bedrock_with_raw_response.py, skipping these tests.
  • Misc:
    • Minor formatting changes in __init__.py and test_bedrock_with_raw_response.py.

This description was created by Ellipsis for 1728094. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Chores
    • Limited Anthropic instrumentation to stable APIs; beta endpoints (including Bedrock) are no longer instrumented.
  • Tests
    • Skipped select async Bedrock tests related to beta and raw-response flows.
  • Style
    • Minor formatting updates to imports, logging messages, and test call layouts; no runtime impact.

Copy link

coderabbitai bot commented Aug 14, 2025

Walkthrough

Disables beta instrumentation entries for Anthropic and Bedrock in the Anthropic OpenTelemetry integration and marks several Bedrock raw-response tests as skipped. Additional non-functional formatting and logging string layout adjustments were made.

Changes

Cohort / File(s) Summary of changes
Anthropic instrumentation config
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py
Commented out beta entries in WRAPPED_METHODS and WRAPPED_AMETHODS (regular Anthropic and Bedrock), reducing instrumented endpoints; reformatted imports and log strings; whitespace-only edits; no API signature changes.
Tests: Bedrock raw response (async)
packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py
Added pytest skip markers to three async Bedrock tests; reformatted parameter lists and await calls; minor style edits; functional behavior unchanged except tests now skipped.

Sequence Diagram(s)

sequenceDiagram
  actor Dev as Developer Code
  participant App as Application
  participant Inst as OTel Anthropic Instrumentation
  participant SDK as Anthropic/Bedrock SDK

  Note over App,SDK: Previous behavior (beta enabled)
  App->>Inst: Call beta SDK method
  Inst->>SDK: Wrapped call (start span, attrs)
  SDK-->>Inst: Response
  Inst-->>App: Response (span ended)

  Note over App,SDK: Current behavior (beta disabled)
  App->>SDK: Call beta SDK method (no wrap)
  SDK-->>App: Response (no span)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • doronkopit5

Poem

In cables quiet, I hop through trace,
Snipping beta paths with gentle grace.
Tests now nap, their carrots saved,
Spans grow fewer, routes behaved.
With twitches, logs align just right—
A rabbit tidies code by night. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gk/temp-disable-beta-anthropic

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@galkleinman galkleinman changed the title temp(anthropic): disable beta apis instrumentation fix(anthropic): temp disable beta apis instrumentation Aug 14, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 1728094 in 2 minutes and 38 seconds. Click for details.
  • Reviewed 286 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 6 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py:443
  • Draft comment:
    The multi-line import syntax (e.g. for aset_response_attributes) improves readability. Good job keeping a consistent import style.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py:28
  • Draft comment:
    Beta API tests are marked as skipped. If beta instrumentation is permanently disabled, consider removing these tests to keep the suite clear and maintainable.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment is partially incorrect - only one of the three skipped tests is actually a beta API test. The other two are regular API tests. The comment makes assumptions about why the tests are skipped without clear evidence. We don't know from the diff why these tests were skipped - it could be temporary. The comment raises a valid point about test maintenance, but makes incorrect assumptions about which tests are beta tests. I could be missing context about why these tests were skipped. Given the rules state we should only keep comments with strong evidence they are correct, this comment's incorrect assumptions and speculative nature make it unsuitable. Delete the comment because it makes incorrect assumptions about which tests are beta tests and speculates about the reason for skipping without evidence.
3. packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py:61
  • Draft comment:
    The multi-line formatting for extracting response content improves readability. Nice cleanup!
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
4. packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py:84
  • Draft comment:
    Typographical error: The comment marker has an extra '#' at the beginning. Consider using a single '#' for consistency, e.g. '# Beta API methods (regular Anthropic SDK)'.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50% The double # appears to be intentional - it's used to comment out an entire block of code while preserving the original comment structure. The first # is part of the block comment-out, while the second # is the original comment marker. This is a common and valid practice when temporarily disabling code blocks. Could I be wrong about the intention? Maybe the double # was accidental. But given the systematic use of double # throughout the commented out block, it seems clearly intentional. The systematic and consistent use of double # throughout multiple blocks strongly suggests this is intentional code commenting, not a typo. The comment should be deleted as it misunderstands intentional code commenting structure.
5. packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py:97
  • Draft comment:
    Typographical error: The comment marker here has an extra '#' at the beginning. Suggest using a single '#' for clarity, e.g. '# Beta API methods (Bedrock SDK)'.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50% The double # appears to be intentional as it's used consistently throughout multiple blocks of commented code. This is a common Python style to indicate a block of code that is more permanently commented out vs a single # for regular comments. The comment is suggesting a style change that would actually make the code less clear. Could the double # actually be intentional to distinguish these commented blocks from regular comments? Looking at the full context, that seems to be the case. Yes, the double # is clearly intentional and consistent throughout the file. This is not a typographical error but a deliberate style choice. The comment should be deleted as it incorrectly identifies an intentional style choice as an error.
6. packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py:125
  • Draft comment:
    Typographical issue: There appears to be an extra '#' character in the comment on this line ("# # Beta API async methods (regular Anthropic SDK)"). Please remove one '#' if this is unintentional.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50% The double '#' appears to be intentional formatting to show comment hierarchy. The entire block uses this consistently. The comment is suggesting a change that would actually make the formatting less consistent. Additionally, this is just a style nitpick about comments in commented-out code, which is not particularly important. Could the double '#' be confusing to other developers? Could it violate some Python style guide I'm not aware of? Even if it's not standard Python style, this is clearly an intentional formatting choice made consistently throughout the file. The benefit of consistency outweighs any style guide concerns, especially for commented out code. Delete this comment. It's suggesting a change that would make the code less consistent, and it's a trivial style issue about comments in commented-out code.

Workflow ID: wflow_ub8Y5I4tafbwjIUL

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

"method": "stream",
"span_name": "anthropic.chat",
},
# # Beta API methods (regular Anthropic SDK)
Copy link
Contributor

Choose a reason for hiding this comment

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

Temporarily disabled beta API instrumentation by commenting out blocks. Consider using a feature flag or config option to conditionally enable beta instrumentation instead of leaving commented-out code.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py (1)

125-151: Mirror the feature-flag approach for async beta entries

Apply the same opt-in gating for async wrappers to keep the behavior consistent.

-    # # Beta API async methods (regular Anthropic SDK)
-    # {
-    #     "package": "anthropic.resources.beta.messages.messages",
-    #     "object": "AsyncMessages",
-    #     "method": "create",
-    #     "span_name": "anthropic.chat",
-    # },
-    # {
-    #     "package": "anthropic.resources.beta.messages.messages",
-    #     "object": "AsyncMessages",
-    #     "method": "stream",
-    #     "span_name": "anthropic.chat",
-    # },
-    # # Beta API async methods (Bedrock SDK)
-    # {
-    #     "package": "anthropic.lib.bedrock._beta_messages",
-    #     "object": "AsyncMessages",
-    #     "method": "create",
-    #     "span_name": "anthropic.chat",
-    # },
-    # {
-    #     "package": "anthropic.lib.bedrock._beta_messages",
-    #     "object": "AsyncMessages",
-    #     "method": "stream",
-    #     "span_name": "anthropic.chat",
-    # },
+    # Optionally enable beta API instrumentation for async methods
+    *(
+        [
+            {
+                "package": "anthropic.resources.beta.messages.messages",
+                "object": "AsyncMessages",
+                "method": "create",
+                "span_name": "anthropic.chat",
+            },
+            {
+                "package": "anthropic.resources.beta.messages.messages",
+                "object": "AsyncMessages",
+                "method": "stream",
+                "span_name": "anthropic.chat",
+            },
+            {
+                "package": "anthropic.lib.bedrock._beta_messages",
+                "object": "AsyncMessages",
+                "method": "create",
+                "span_name": "anthropic.chat",
+            },
+            {
+                "package": "anthropic.lib.bedrock._beta_messages",
+                "object": "AsyncMessages",
+                "method": "stream",
+                "span_name": "anthropic.chat",
+            },
+        ]
+        if os.getenv("TRACELOOP_ENABLE_ANTHROPIC_BETA", "false").lower() == "true"
+        else []
+    ),
🧹 Nitpick comments (5)
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py (2)

84-110: Prefer feature-flag gating over commented-out beta entries

Commenting out list entries is brittle. Gate the beta wrap entries behind an env/config flag so they can be re-enabled without code churn and to keep the list consistent.

Apply this diff to make beta entries opt-in via a flag (keeps them disabled by default):

-    # # Beta API methods (regular Anthropic SDK)
-    # {
-    #     "package": "anthropic.resources.beta.messages.messages",
-    #     "object": "Messages",
-    #     "method": "create",
-    #     "span_name": "anthropic.chat",
-    # },
-    # {
-    #     "package": "anthropic.resources.beta.messages.messages",
-    #     "object": "Messages",
-    #     "method": "stream",
-    #     "span_name": "anthropic.chat",
-    # },
-    # # Beta API methods (Bedrock SDK)
-    # {
-    #     "package": "anthropic.lib.bedrock._beta_messages",
-    #     "object": "Messages",
-    #     "method": "create",
-    #     "span_name": "anthropic.chat",
-    # },
-    # {
-    #     "package": "anthropic.lib.bedrock._beta_messages",
-    #     "object": "Messages",
-    #     "method": "stream",
-    #     "span_name": "anthropic.chat",
-    # },
+    # Optionally enable beta API instrumentation if explicitly requested
+    *(
+        [
+            {
+                "package": "anthropic.resources.beta.messages.messages",
+                "object": "Messages",
+                "method": "create",
+                "span_name": "anthropic.chat",
+            },
+            {
+                "package": "anthropic.resources.beta.messages.messages",
+                "object": "Messages",
+                "method": "stream",
+                "span_name": "anthropic.chat",
+            },
+            {
+                "package": "anthropic.lib.bedrock._beta_messages",
+                "object": "Messages",
+                "method": "create",
+                "span_name": "anthropic.chat",
+            },
+            {
+                "package": "anthropic.lib.bedrock._beta_messages",
+                "object": "Messages",
+                "method": "stream",
+                "span_name": "anthropic.chat",
+            },
+        ]
+        if os.getenv("TRACELOOP_ENABLE_ANTHROPIC_BETA", "false").lower() == "true"
+        else []
+    ),

Follow-up: If you prefer a code-level toggle, consider a Config flag instead of env.


785-791: Avoid f-strings in logging to preserve lazy interpolation

Using f-strings eagerly formats the message even when DEBUG is disabled. Prefer %s-style arguments to leverage the logger’s lazy formatting.

-                logger.debug(
-                    f"Successfully wrapped {wrap_package}.{wrap_object}.{wrap_method}"
-                )
+                logger.debug(
+                    "Successfully wrapped %s.%s.%s",
+                    wrap_package,
+                    wrap_object,
+                    wrap_method,
+                )
             except Exception as e:
-                logger.debug(
-                    f"Failed to wrap {wrap_package}.{wrap_object}.{wrap_method}: {e}"
-                )
+                logger.debug(
+                    "Failed to wrap %s.%s.%s: %s",
+                    wrap_package,
+                    wrap_object,
+                    wrap_method,
+                    e,
+                )
packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py (3)

28-28: Add an explicit skip reason for traceability

Provide context on why this test is skipped and when to re-enable.

-@pytest.mark.skip
+@pytest.mark.skip(reason="Temporarily disabled: Bedrock/raw-response instrumentation is off in PR #3258")

83-83: Add an explicit skip reason for this test as well

Helps future maintainers understand why it's skipped.

-@pytest.mark.skip
+@pytest.mark.skip(reason="Temporarily disabled: Bedrock instrumentation paths are not wrapped in PR #3258")

132-132: Add an explicit skip reason for the beta-with-raw-response test

Same rationale as above.

-@pytest.mark.skip
+@pytest.mark.skip(reason="Temporarily disabled: Anthropic beta Bedrock instrumentation disabled in PR #3258")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 57b67b1 and 1728094.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py (7 hunks)
  • packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: Python code must conform to Flake8 linting rules
Do not hardcode API keys in source code; read them from environment variables or a secure vault

Files:

  • packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py
  • packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py
🧬 Code Graph Analysis (2)
packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py (1)
packages/opentelemetry-instrumentation-milvus/tests/conftest.py (1)
  • reader (37-41)
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py (2)
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/span_utils.py (1)
  • aset_response_attributes (307-328)
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/utils.py (1)
  • ashared_metrics_attributes (138-147)
🔇 Additional comments (10)
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py (4)

186-186: No-op/whitespace-only change

No functional impact. Nothing to do.


280-280: No-op/whitespace-only change

No functional impact. Nothing to do.


448-451: Function-local import to avoid circular dependency is acceptable

Moving aset_response_attributes import into the coroutine avoids import-time cycles (span_utils imports back into this module). This is a reasonable trade-off; the overhead is negligible on the happy path.


677-680: Deferred import to prevent cycles for async metrics attributes is fine

Lazy-importing ashared_metrics_attributes here is acceptable and keeps module import clean.

packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py (6)

24-25: Trailing comma in fixture call is fine

No behavioral change; keeps diffs cleaner on future edits.


32-37: Parameter reflow is fine

Formatting-only; no behavior change.


61-65: LGTM: robust raw-response content extraction

The hasattr(response, "parse") guard is a pragmatic way to deal with raw responses vs parsed objects.


87-92: Confirm intention to skip non-beta Bedrock regular create

This test targets regular messages.create on Bedrock, not a beta endpoint. Are we disabling Bedrock instrumentation entirely (not only beta)? If not, consider keeping this test active.

If the intent is to skip only when Bedrock is not instrumented, convert to a conditional skip:

-@pytest.mark.skip
+@pytest.mark.skipif(
+    os.getenv("TRACELOOP_ENABLE_ANTHROPIC_BEDROCK", "false").lower() != "true",
+    reason="Bedrock instrumentation disabled",
+)

Alternatively, if Bedrock instrumentation truly isn’t supported now, keep it skipped but document the reason (see the previous comment).


136-141: Multiline await call improves readability

Parenthesized, multiline style in the await call is fine and keeps arguments diff-friendly.

Also applies to: 143-154


167-171: LGTM: consistent content extraction for raw responses

Matches the earlier test; keeps behavior consistent across raw/parsed responses.

Comment on lines +84 to 110
# # Beta API methods (regular Anthropic SDK)
# {
# "package": "anthropic.resources.beta.messages.messages",
# "object": "Messages",
# "method": "create",
# "span_name": "anthropic.chat",
# },
# {
# "package": "anthropic.resources.beta.messages.messages",
# "object": "Messages",
# "method": "stream",
# "span_name": "anthropic.chat",
# },
# # Beta API methods (Bedrock SDK)
# {
# "package": "anthropic.lib.bedrock._beta_messages",
# "object": "Messages",
# "method": "create",
# "span_name": "anthropic.chat",
# },
# {
# "package": "anthropic.lib.bedrock._beta_messages",
# "object": "Messages",
# "method": "stream",
# "span_name": "anthropic.chat",
# },
]
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Sanity-check: ensure no remaining references to now-disabled beta wrappers

Since beta wrappers are disabled, verify there are no left-over tests or code paths expecting those spans.

Run this script to locate potential references to disabled beta APIs across the repo:

Also applies to: 125-151


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find beta messages and bedrock beta wrapper usages
rg -n -A2 -B2 'resources\.beta\.messages|lib\.bedrock\._beta_messages' || true

# Find bedrock async client usages to inspect related tests
rg -n -A3 -B3 'AsyncAnthropicBedrock|with_raw_response' || true

Length of output: 24853


Remove stale beta wrapper references

The tests and commented‐out code for beta wrappers remain in the repo even though beta spans are now disabled. Please clean these up:

• packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/init.py
– Lines 84–110 and 125–151: commented‐out beta API entries for both regular and async methods.
→ Consider deleting these blocks if they’re no longer needed.

• packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py
– Lines 132–147: test_async_anthropic_bedrock_beta_with_raw_response still invokes async_anthropic_bedrock_client.beta.messages.with_raw_response.create.
→ Remove or adapt this test to reflect that beta wrappers have been disabled.

🤖 Prompt for AI Agents
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py
lines 84–110 and 125–151: the file contains stale, commented-out beta API
wrapper entries for regular and async methods; delete these commented blocks to
remove dead code and keep the file clean.
packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py
lines 132–147: the test calls
async_anthropic_bedrock_client.beta.messages.with_raw_response.create which
relies on disabled beta wrappers; remove or modify this test to call the
supported non-beta API (or delete the test if no equivalent exists) and update
any assertions accordingly.

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.

2 participants