@@ -76,6 +76,21 @@ def _calculate_token_usage(result, span):
7676 record_token_usage (span , input_tokens , output_tokens , total_tokens )
7777
7878
79+ def _get_responses (content ):
80+ # type: (list[dict[str, str]]) -> dict[str, str]
81+ """Get JSON of a Anthropic responses."""
82+ responses = []
83+ for item in content :
84+ if hasattr (item , "text" ):
85+ responses .append (
86+ {
87+ "type" : item .type ,
88+ "text" : item .text ,
89+ }
90+ )
91+ return responses
92+
93+
7994def _wrap_message_create (f ):
8095 # type: (Any) -> Any
8196 @wraps (f )
@@ -115,18 +130,7 @@ def _sentry_patched_create(*args, **kwargs):
115130 span .set_data (SPANDATA .AI_INPUT_MESSAGES , messages )
116131 if hasattr (result , "content" ):
117132 if should_send_default_pii () and integration .include_prompts :
118- span .set_data (
119- SPANDATA .AI_RESPONSES ,
120- list (
121- map (
122- lambda message : {
123- "type" : message .type ,
124- "text" : message .text ,
125- },
126- result .content ,
127- )
128- ),
129- )
133+ span .set_data (SPANDATA .AI_RESPONSES , _get_responses (result .content ))
130134 _calculate_token_usage (result , span )
131135 span .__exit__ (None , None , None )
132136 elif hasattr (result , "_iterator" ):
@@ -149,8 +153,6 @@ def new_iterator():
149153 elif event .type == "content_block_delta" :
150154 if hasattr (event .delta , "text" ):
151155 content_blocks .append (event .delta .text )
152- elif hasattr (event .delta , "partial_json" ):
153- content_blocks .append (event .delta .partial_json )
154156 elif event .type == "content_block_stop" :
155157 pass
156158 elif event .type == "message_delta" :
0 commit comments