|
81 | 81 | "method": "stream",
|
82 | 82 | "span_name": "anthropic.chat",
|
83 | 83 | },
|
84 |
| - # Beta API methods (regular Anthropic SDK) |
85 |
| - { |
86 |
| - "package": "anthropic.resources.beta.messages.messages", |
87 |
| - "object": "Messages", |
88 |
| - "method": "create", |
89 |
| - "span_name": "anthropic.chat", |
90 |
| - }, |
91 |
| - { |
92 |
| - "package": "anthropic.resources.beta.messages.messages", |
93 |
| - "object": "Messages", |
94 |
| - "method": "stream", |
95 |
| - "span_name": "anthropic.chat", |
96 |
| - }, |
97 |
| - # Beta API methods (Bedrock SDK) |
98 |
| - { |
99 |
| - "package": "anthropic.lib.bedrock._beta_messages", |
100 |
| - "object": "Messages", |
101 |
| - "method": "create", |
102 |
| - "span_name": "anthropic.chat", |
103 |
| - }, |
104 |
| - { |
105 |
| - "package": "anthropic.lib.bedrock._beta_messages", |
106 |
| - "object": "Messages", |
107 |
| - "method": "stream", |
108 |
| - "span_name": "anthropic.chat", |
109 |
| - }, |
| 84 | + # # Beta API methods (regular Anthropic SDK) |
| 85 | + # { |
| 86 | + # "package": "anthropic.resources.beta.messages.messages", |
| 87 | + # "object": "Messages", |
| 88 | + # "method": "create", |
| 89 | + # "span_name": "anthropic.chat", |
| 90 | + # }, |
| 91 | + # { |
| 92 | + # "package": "anthropic.resources.beta.messages.messages", |
| 93 | + # "object": "Messages", |
| 94 | + # "method": "stream", |
| 95 | + # "span_name": "anthropic.chat", |
| 96 | + # }, |
| 97 | + # # Beta API methods (Bedrock SDK) |
| 98 | + # { |
| 99 | + # "package": "anthropic.lib.bedrock._beta_messages", |
| 100 | + # "object": "Messages", |
| 101 | + # "method": "create", |
| 102 | + # "span_name": "anthropic.chat", |
| 103 | + # }, |
| 104 | + # { |
| 105 | + # "package": "anthropic.lib.bedrock._beta_messages", |
| 106 | + # "object": "Messages", |
| 107 | + # "method": "stream", |
| 108 | + # "span_name": "anthropic.chat", |
| 109 | + # }, |
110 | 110 | ]
|
111 | 111 |
|
112 | 112 | WRAPPED_AMETHODS = [
|
|
122 | 122 | "method": "create",
|
123 | 123 | "span_name": "anthropic.chat",
|
124 | 124 | },
|
125 |
| - # Beta API async methods (regular Anthropic SDK) |
126 |
| - { |
127 |
| - "package": "anthropic.resources.beta.messages.messages", |
128 |
| - "object": "AsyncMessages", |
129 |
| - "method": "create", |
130 |
| - "span_name": "anthropic.chat", |
131 |
| - }, |
132 |
| - { |
133 |
| - "package": "anthropic.resources.beta.messages.messages", |
134 |
| - "object": "AsyncMessages", |
135 |
| - "method": "stream", |
136 |
| - "span_name": "anthropic.chat", |
137 |
| - }, |
138 |
| - # Beta API async methods (Bedrock SDK) |
139 |
| - { |
140 |
| - "package": "anthropic.lib.bedrock._beta_messages", |
141 |
| - "object": "AsyncMessages", |
142 |
| - "method": "create", |
143 |
| - "span_name": "anthropic.chat", |
144 |
| - }, |
145 |
| - { |
146 |
| - "package": "anthropic.lib.bedrock._beta_messages", |
147 |
| - "object": "AsyncMessages", |
148 |
| - "method": "stream", |
149 |
| - "span_name": "anthropic.chat", |
150 |
| - }, |
| 125 | + # # Beta API async methods (regular Anthropic SDK) |
| 126 | + # { |
| 127 | + # "package": "anthropic.resources.beta.messages.messages", |
| 128 | + # "object": "AsyncMessages", |
| 129 | + # "method": "create", |
| 130 | + # "span_name": "anthropic.chat", |
| 131 | + # }, |
| 132 | + # { |
| 133 | + # "package": "anthropic.resources.beta.messages.messages", |
| 134 | + # "object": "AsyncMessages", |
| 135 | + # "method": "stream", |
| 136 | + # "span_name": "anthropic.chat", |
| 137 | + # }, |
| 138 | + # # Beta API async methods (Bedrock SDK) |
| 139 | + # { |
| 140 | + # "package": "anthropic.lib.bedrock._beta_messages", |
| 141 | + # "object": "AsyncMessages", |
| 142 | + # "method": "create", |
| 143 | + # "span_name": "anthropic.chat", |
| 144 | + # }, |
| 145 | + # { |
| 146 | + # "package": "anthropic.lib.bedrock._beta_messages", |
| 147 | + # "object": "AsyncMessages", |
| 148 | + # "method": "stream", |
| 149 | + # "span_name": "anthropic.chat", |
| 150 | + # }, |
151 | 151 | ]
|
152 | 152 |
|
153 | 153 |
|
@@ -183,6 +183,7 @@ async def _aset_token_usage(
|
183 | 183 | choice_counter: Counter = None,
|
184 | 184 | ):
|
185 | 185 | from opentelemetry.instrumentation.anthropic.utils import _aextract_response_data
|
| 186 | + |
186 | 187 | response = await _aextract_response_data(response)
|
187 | 188 |
|
188 | 189 | if usage := response.get("usage"):
|
@@ -276,6 +277,7 @@ def _set_token_usage(
|
276 | 277 | choice_counter: Counter = None,
|
277 | 278 | ):
|
278 | 279 | from opentelemetry.instrumentation.anthropic.utils import _extract_response_data
|
| 280 | + |
279 | 281 | response = _extract_response_data(response)
|
280 | 282 |
|
281 | 283 | if usage := response.get("usage"):
|
@@ -443,7 +445,10 @@ async def _ahandle_response(span: Span, event_logger: Optional[EventLogger], res
|
443 | 445 | else:
|
444 | 446 | if not span.is_recording():
|
445 | 447 | return
|
446 |
| - from opentelemetry.instrumentation.anthropic.span_utils import aset_response_attributes |
| 448 | + from opentelemetry.instrumentation.anthropic.span_utils import ( |
| 449 | + aset_response_attributes, |
| 450 | + ) |
| 451 | + |
447 | 452 | await aset_response_attributes(span, response)
|
448 | 453 |
|
449 | 454 |
|
@@ -669,7 +674,10 @@ async def _awrap(
|
669 | 674 | kwargs,
|
670 | 675 | )
|
671 | 676 | elif response:
|
672 |
| - from opentelemetry.instrumentation.anthropic.utils import ashared_metrics_attributes |
| 677 | + from opentelemetry.instrumentation.anthropic.utils import ( |
| 678 | + ashared_metrics_attributes, |
| 679 | + ) |
| 680 | + |
673 | 681 | metric_attributes = await ashared_metrics_attributes(response)
|
674 | 682 |
|
675 | 683 | if duration_histogram:
|
@@ -774,9 +782,13 @@ def _instrument(self, **kwargs):
|
774 | 782 | wrapped_method,
|
775 | 783 | ),
|
776 | 784 | )
|
777 |
| - logger.debug(f"Successfully wrapped {wrap_package}.{wrap_object}.{wrap_method}") |
| 785 | + logger.debug( |
| 786 | + f"Successfully wrapped {wrap_package}.{wrap_object}.{wrap_method}" |
| 787 | + ) |
778 | 788 | except Exception as e:
|
779 |
| - logger.debug(f"Failed to wrap {wrap_package}.{wrap_object}.{wrap_method}: {e}") |
| 789 | + logger.debug( |
| 790 | + f"Failed to wrap {wrap_package}.{wrap_object}.{wrap_method}: {e}" |
| 791 | + ) |
780 | 792 | pass # that's ok, we don't want to fail if some methods do not exist
|
781 | 793 |
|
782 | 794 | for wrapped_method in WRAPPED_AMETHODS:
|
|
0 commit comments