-
Notifications
You must be signed in to change notification settings - Fork 955
fix(anthropic): temp disable beta apis instrumentation #3258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,32 +81,32 @@ | |
| "method": "stream", | ||
| "span_name": "anthropic.chat", | ||
| }, | ||
| # 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", | ||
| }, | ||
| # # 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", | ||
| # }, | ||
| ] | ||
|
Comment on lines
+84
to
110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainSanity-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' || trueLength 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 • packages/opentelemetry-instrumentation-anthropic/tests/test_bedrock_with_raw_response.py 🤖 Prompt for AI Agents |
||
|
|
||
| WRAPPED_AMETHODS = [ | ||
|
|
@@ -122,32 +122,32 @@ | |
| "method": "create", | ||
| "span_name": "anthropic.chat", | ||
| }, | ||
| # 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", | ||
| }, | ||
| # # 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", | ||
| # }, | ||
| ] | ||
|
|
||
|
|
||
|
|
@@ -183,6 +183,7 @@ async def _aset_token_usage( | |
| choice_counter: Counter = None, | ||
| ): | ||
| from opentelemetry.instrumentation.anthropic.utils import _aextract_response_data | ||
|
|
||
| response = await _aextract_response_data(response) | ||
|
|
||
| if usage := response.get("usage"): | ||
|
|
@@ -276,6 +277,7 @@ def _set_token_usage( | |
| choice_counter: Counter = None, | ||
| ): | ||
| from opentelemetry.instrumentation.anthropic.utils import _extract_response_data | ||
|
|
||
| response = _extract_response_data(response) | ||
|
|
||
| if usage := response.get("usage"): | ||
|
|
@@ -443,7 +445,10 @@ async def _ahandle_response(span: Span, event_logger: Optional[EventLogger], res | |
| else: | ||
| if not span.is_recording(): | ||
| return | ||
| from opentelemetry.instrumentation.anthropic.span_utils import aset_response_attributes | ||
| from opentelemetry.instrumentation.anthropic.span_utils import ( | ||
| aset_response_attributes, | ||
| ) | ||
|
|
||
| await aset_response_attributes(span, response) | ||
|
|
||
|
|
||
|
|
@@ -669,7 +674,10 @@ async def _awrap( | |
| kwargs, | ||
| ) | ||
| elif response: | ||
| from opentelemetry.instrumentation.anthropic.utils import ashared_metrics_attributes | ||
| from opentelemetry.instrumentation.anthropic.utils import ( | ||
| ashared_metrics_attributes, | ||
| ) | ||
|
|
||
| metric_attributes = await ashared_metrics_attributes(response) | ||
|
|
||
| if duration_histogram: | ||
|
|
@@ -774,9 +782,13 @@ def _instrument(self, **kwargs): | |
| wrapped_method, | ||
| ), | ||
| ) | ||
| logger.debug(f"Successfully wrapped {wrap_package}.{wrap_object}.{wrap_method}") | ||
| logger.debug( | ||
| f"Successfully wrapped {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( | ||
| f"Failed to wrap {wrap_package}.{wrap_object}.{wrap_method}: {e}" | ||
| ) | ||
| pass # that's ok, we don't want to fail if some methods do not exist | ||
|
|
||
| for wrapped_method in WRAPPED_AMETHODS: | ||
|
|
||
There was a problem hiding this comment.
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.