|
26 | 26 | from sentry_sdk.consts import SPANDATA |
27 | 27 | from sentry_sdk.integrations import DidNotEnable, Integration |
28 | 28 | from sentry_sdk.scope import should_send_default_pii |
29 | | -from sentry_sdk.tracing_utils import set_span_errored |
30 | 29 | from sentry_sdk.utils import ( |
31 | 30 | capture_internal_exceptions, |
32 | 31 | event_from_exception, |
@@ -133,11 +132,6 @@ def count_tokens(self: "OpenAIIntegration", s: str) -> int: |
133 | 132 |
|
134 | 133 |
|
135 | 134 | def _capture_exception(exc: "Any") -> None: |
136 | | - # Close an eventually open span |
137 | | - # We need to do this by hand because we are not using the start_span context manager |
138 | | - current_span = sentry_sdk.get_current_span() |
139 | | - set_span_errored(current_span) |
140 | | - |
141 | 135 | event, hint = event_from_exception( |
142 | 136 | exc, |
143 | 137 | client_options=sentry_sdk.get_client().options, |
@@ -697,7 +691,7 @@ def _new_sync_chat_completion(f: "Any", *args: "Any", **kwargs: "Any") -> "Any": |
697 | 691 | exc_info = sys.exc_info() |
698 | 692 | with capture_internal_exceptions(): |
699 | 693 | _capture_exception(exc) |
700 | | - span.__exit__(None, None, None) |
| 694 | + span.__exit__(*exc_info) |
701 | 695 | reraise(*exc_info) |
702 | 696 |
|
703 | 697 | # Attribute check to fail gracefully if the attribute is not present in future `openai` versions. |
@@ -781,7 +775,7 @@ async def _new_async_chat_completion(f: "Any", *args: "Any", **kwargs: "Any") -> |
781 | 775 | exc_info = sys.exc_info() |
782 | 776 | with capture_internal_exceptions(): |
783 | 777 | _capture_exception(exc) |
784 | | - span.__exit__(None, None, None) |
| 778 | + span.__exit__(*exc_info) |
785 | 779 | reraise(*exc_info) |
786 | 780 |
|
787 | 781 | # Attribute check to fail gracefully if the attribute is not present in future `openai` versions. |
@@ -1280,7 +1274,7 @@ def _new_sync_responses_create(f: "Any", *args: "Any", **kwargs: "Any") -> "Any" |
1280 | 1274 | exc_info = sys.exc_info() |
1281 | 1275 | with capture_internal_exceptions(): |
1282 | 1276 | _capture_exception(exc) |
1283 | | - span.__exit__(None, None, None) |
| 1277 | + span.__exit__(*exc_info) |
1284 | 1278 | reraise(*exc_info) |
1285 | 1279 |
|
1286 | 1280 | # Attribute check to fail gracefully if the attribute is not present in future `openai` versions. |
@@ -1354,7 +1348,7 @@ async def _new_async_responses_create(f: "Any", *args: "Any", **kwargs: "Any") - |
1354 | 1348 | exc_info = sys.exc_info() |
1355 | 1349 | with capture_internal_exceptions(): |
1356 | 1350 | _capture_exception(exc) |
1357 | | - span.__exit__(None, None, None) |
| 1351 | + span.__exit__(*exc_info) |
1358 | 1352 | reraise(*exc_info) |
1359 | 1353 |
|
1360 | 1354 | # Attribute check to fail gracefully if the attribute is not present in future `openai` versions. |
|
0 commit comments