Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sentry_sdk/integrations/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def count_tokens(self, s):
return 0


def _capture_exception(exc):
# type: (Any) -> None
def _capture_exception(exc, manual_span_cleanup=True):
# type: (Any, bool) -> None
# Close an eventually open span
# We need to do this by hand because we are not using the start_span context manager
current_span = sentry_sdk.get_current_span()
if current_span is not None:
if manual_span_cleanup and current_span is not None:
current_span.__exit__(None, None, None)

event, hint = event_from_exception(
Expand Down Expand Up @@ -516,7 +516,7 @@ def _execute_sync(f, *args, **kwargs):
try:
result = f(*args, **kwargs)
except Exception as e:
_capture_exception(e)
_capture_exception(e, manual_span_cleanup=False)
raise e from None

return gen.send(result)
Expand Down Expand Up @@ -550,7 +550,7 @@ async def _execute_async(f, *args, **kwargs):
try:
result = await f(*args, **kwargs)
except Exception as e:
_capture_exception(e)
_capture_exception(e, manual_span_cleanup=False)
raise e from None

return gen.send(result)
Expand Down
Loading