Skip to content

Commit 1c9ee52

Browse files
move finish_reasons out
1 parent 7c01a32 commit 1c9ee52

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

sentry_sdk/integrations/langchain.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -561,25 +561,23 @@ def on_llm_end(
561561
except IndexError:
562562
generation = None
563563

564-
if isinstance(generation, ChatGeneration):
565-
set_on_span = (
566-
span.set_attribute
567-
if isinstance(span, StreamedSpan)
568-
else span.set_data
569-
)
564+
set_on_span = (
565+
span.set_attribute if isinstance(span, StreamedSpan) else span.set_data
566+
)
570567

568+
if generation.generation_info is not None:
569+
finish_reason = generation.generation_info.get("finish_reason")
570+
if finish_reason is not None:
571+
set_on_span(
572+
SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS,
573+
[finish_reason],
574+
)
575+
576+
if isinstance(generation, ChatGeneration):
571577
response_model = generation.message.response_metadata.get("model_name")
572578
if response_model is not None:
573579
set_on_span(SPANDATA.GEN_AI_RESPONSE_MODEL, response_model)
574580

575-
if generation.generation_info is not None:
576-
finish_reason = generation.generation_info.get("finish_reason")
577-
if finish_reason is not None:
578-
set_on_span(
579-
SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS,
580-
[finish_reason],
581-
)
582-
583581
if should_send_default_pii() and self.include_prompts:
584582
tool_calls = getattr(generation.message, "tool_calls", None)
585583
if tool_calls is not None and tool_calls != []:

0 commit comments

Comments
 (0)