Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 4 additions & 10 deletions sentry_sdk/integrations/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing_utils import set_span_errored
from sentry_sdk.utils import (
capture_internal_exceptions,
event_from_exception,
Expand Down Expand Up @@ -133,11 +132,6 @@ def count_tokens(self: "OpenAIIntegration", s: str) -> int:


def _capture_exception(exc: "Any") -> 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()
set_span_errored(current_span)

event, hint = event_from_exception(
exc,
client_options=sentry_sdk.get_client().options,
Expand Down Expand Up @@ -707,7 +701,7 @@ def _new_sync_chat_completion(f: "Any", *args: "Any", **kwargs: "Any") -> "Any":
exc_info = sys.exc_info()
with capture_internal_exceptions():
_capture_exception(exc)
span.__exit__(None, None, None)
span.__exit__(*exc_info)
reraise(*exc_info)

# Attribute check to fail gracefully if the attribute is not present in future `openai` versions.
Expand Down Expand Up @@ -775,7 +769,7 @@ async def _new_async_chat_completion(f: "Any", *args: "Any", **kwargs: "Any") ->
exc_info = sys.exc_info()
with capture_internal_exceptions():
_capture_exception(exc)
span.__exit__(None, None, None)
span.__exit__(*exc_info)
reraise(*exc_info)

# Attribute check to fail gracefully if the attribute is not present in future `openai` versions.
Expand Down Expand Up @@ -1257,7 +1251,7 @@ def _new_sync_responses_create(f: "Any", *args: "Any", **kwargs: "Any") -> "Any"
exc_info = sys.exc_info()
with capture_internal_exceptions():
_capture_exception(exc)
span.__exit__(None, None, None)
span.__exit__(*exc_info)
reraise(*exc_info)

# Attribute check to fail gracefully if the attribute is not present in future `openai` versions.
Expand Down Expand Up @@ -1315,7 +1309,7 @@ async def _new_async_responses_create(f: "Any", *args: "Any", **kwargs: "Any") -
exc_info = sys.exc_info()
with capture_internal_exceptions():
_capture_exception(exc)
span.__exit__(None, None, None)
span.__exit__(*exc_info)
reraise(*exc_info)

# Attribute check to fail gracefully if the attribute is not present in future `openai` versions.
Expand Down
1 change: 0 additions & 1 deletion tests/integrations/openai/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,6 @@ def test_span_status_error(sentry_init, capture_events):
assert error["level"] == "error"
assert transaction["spans"][0]["status"] == "internal_error"
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
assert transaction["contexts"]["trace"]["status"] == "internal_error"


@pytest.mark.asyncio
Expand Down
Loading