feat(anthropic): Record finish reasons in AI monitoring spans (#5678) · gitcommit90/sentry-python@b905cd3 · GitHub
Skip to content

Commit b905cd3

Browse files
ericapisaniclaude
andauthored
feat(anthropic): Record finish reasons in AI monitoring spans (getsentry#5678)
Add `GEN_AI_RESPONSE_FINISH_REASONS` span data to the Anthropic integration by capturing `stop_reason` from API responses. For non-streaming responses, the `stop_reason` is read directly from the `Message` result. For streaming responses, it's extracted from the `MessageDeltaEvent` delta and passed through the `_collect_ai_data` helper. This brings the Anthropic integration in line with the OpenAI integration's finish reason tracking. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6ea663f commit b905cd3

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

sentry_sdk/integrations/anthropic.py

Lines changed: 27 additions & 13 deletions

tests/integrations/anthropic/test_anthropic.py

Lines changed: 13 additions & 4 deletions

0 commit comments

Comments
 (0)