Skip to content

Commit 2c5c2fd

Browse files
committed
resilient
1 parent b0b2331 commit 2c5c2fd

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,23 @@ def _sentry_patched_create_common(f, *args, **kwargs):
208208
with capture_internal_exceptions():
209209
if hasattr(result, "content"):
210210
input_tokens, output_tokens = _get_token_usage(result)
211+
212+
content_blocks = []
213+
for content_block in result.content:
214+
if hasattr(content_block, "to_dict"):
215+
content_blocks.append(content_block.to_dict())
216+
elif hasattr(content_block, "model_dump"):
217+
content_blocks.append(content_block.model_dump())
218+
elif hasattr(content_block, "text"):
219+
content_blocks.append({"type": "text", "text": content_block.text})
220+
211221
_set_output_data(
212222
span=span,
213223
integration=integration,
214224
model=getattr(result, "model", None),
215225
input_tokens=input_tokens,
216226
output_tokens=output_tokens,
217-
content_blocks=[
218-
{
219-
"type": "text",
220-
"text": content_block.text,
221-
}
222-
for content_block in result.content
223-
if hasattr(content_block, "text")
224-
],
227+
content_blocks=content_blocks,
225228
finish_span=True,
226229
)
227230

0 commit comments

Comments
 (0)