fix(openai): Only finish relevant spans in Chat Completions patches by alexander-alderman-webb · Pull Request #6190 · getsentry/sentry-python
Description
OpenAI Completions spans are only created in _new_sync_chat_completion() and _new_async_chat_completion().
Exit spans in these functions when the openai library function raises an exception.
Resolves an edge case where _new_sync_chat_completion() or _new_async_chat_completion() exits early and does not create a span and get_current_span() therefore returns a non-openai span.
Issues
Reminders
- Please add tests to validate your changes, and lint your code using
tox -e linters. - Add GH Issue ID & Linear ID (if applicable)
- PR title should use conventional commit style (
feat:,fix:,ref:,meta:) - For external contributors: CONTRIBUTING.md, Sentry SDK development docs, Discord community