diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 7a5e863e4d..d19d9bbdd5 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -554,7 +554,8 @@ def on_llm_end( finish_reason = generation.generation_info.get("finish_reason") if finish_reason is not None: span.set_data( - SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS, finish_reason + SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS, + [finish_reason], ) except AttributeError: pass diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index 8a8d646113..132da0a9a0 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -297,6 +297,12 @@ def test_langchain_agent( f"and include_prompts={include_prompts}" ) + # Verify finish_reasons is always an array of strings + assert chat_spans[0]["data"][SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS] == [ + "function_call" + ] + assert chat_spans[1]["data"][SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS] == ["stop"] + # Verify that available tools are always recorded regardless of PII settings for chat_span in chat_spans: span_data = chat_span.get("data", {})