Skip to content

Commit 224885d

Browse files
feat(anthropic): Record reasoning parts in output
1 parent dbc50bd commit 224885d

2 files changed

Lines changed: 788 additions & 890 deletions

File tree

‎sentry_sdk/integrations/anthropic.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
ToolUnionParam,
8686
)
8787

88-
from sentry_sdk._types import TextPart
88+
from sentry_sdk._types import ReasoningPart, TextPart
8989

9090
class _PatchedRawMessageStream(Stream[Any]):
9191
_span: Union[Span, StreamedSpan]
@@ -731,30 +731,30 @@ def _set_output_data(
731731
record_outputs = True
732732

733733
if record_outputs:
734-
output_messages: "dict[str, list[Any]]" = {
735-
"response": [],
736-
"tool": [],
737-
}
734+
parts: "list[Union[TextPart, ReasoningPart]]" = []
735+
tool_calls = []
738736

739737
for output in content_blocks:
740738
if output["type"] == "text":
741-
output_messages["response"].append(output["text"])
739+
parts.append({"type": "text", "content": output["text"]})
740+
elif output["type"] == "thinking":
741+
parts.append({"type": "reasoning", "content": output.get("thinking")})
742742
elif output["type"] == "tool_use":
743-
output_messages["tool"].append(output)
743+
tool_calls.append(output)
744744

745-
if len(output_messages["tool"]) > 0:
745+
if len(tool_calls) > 0:
746746
set_data_normalized(
747747
span,
748748
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS,
749-
output_messages["tool"],
749+
tool_calls,
750750
unpack=False,
751751
)
752752

753-
if len(output_messages["response"]) > 0:
753+
if len(parts) > 0:
754754
set_data_normalized(
755755
span,
756-
SPANDATA.GEN_AI_RESPONSE_TEXT,
757-
output_messages["response"],
756+
SPANDATA.GEN_AI_OUTPUT_MESSAGES,
757+
[{"role": "assistant", "parts": parts}],
758758
unpack=False,
759759
)
760760

0 commit comments

Comments
 (0)