diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 669cc56e87..651a3d7068 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -364,7 +364,7 @@ def on_tool_end(self, output, *, run_id, **kwargs): if not span_data: return if should_send_default_pii() and self.include_prompts: - set_data_normalized(span_data.span, SPANDATA.AI_RESPONSES, [output]) + set_data_normalized(span_data.span, SPANDATA.AI_RESPONSES, output) span_data.span.__exit__(None, None, None) del self.span_map[run_id] diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index e3d6d8e39d..462788ce19 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -78,9 +78,9 @@ def _calculate_chat_completion_usage( messages, response, span, streaming_message_responses=None ): # type: (Iterable[ChatCompletionMessageParam], Any, Span, Optional[List[str]]) -> None - completion_tokens = 0 - prompt_tokens = 0 - total_tokens = 0 + completion_tokens = 0 # type: Optional[int] + prompt_tokens = 0 # type: Optional[int] + total_tokens = 0 # type: Optional[int] if hasattr(response, "usage"): if hasattr(response.usage, "completion_tokens") and isinstance( response.usage.completion_tokens, int diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index 14e01a9a15..b3ca452267 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -149,9 +149,9 @@ def test_langchain_agent( "You are very powerful" in chat_spans[0]["data"]["ai.input_messages"][0]["content"] ) - assert "5" in chat_spans[0]["data"]["ai.responses"][0] + assert "5" in chat_spans[0]["data"]["ai.responses"] assert "word" in tool_exec_span["data"]["ai.input_messages"] - assert "5" in tool_exec_span["data"]["ai.responses"][0] + assert 5 == int(tool_exec_span["data"]["ai.responses"]) assert ( "You are very powerful" in chat_spans[1]["data"]["ai.input_messages"][0]["content"]