diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index 8f0b95e045..901fa403c8 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -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, @@ -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, @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index 677beb5681..f758d0138f 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -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