Skip to content

Commit 426d20c

Browse files
authored
Merge branch 'master' into ivana/dont-iter-random-objects
2 parents 30f9d74 + 4f3b56a commit 426d20c

5 files changed

Lines changed: 11 additions & 21 deletions

File tree

sentry_sdk/integrations/cohere.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from sentry_sdk.ai.monitoring import record_token_usage
77
from sentry_sdk.ai.utils import get_start_span_function, set_data_normalized
88
from sentry_sdk.consts import SPANDATA
9-
from sentry_sdk.tracing_utils import set_span_errored
109

1110
if TYPE_CHECKING:
1211
from typing import Any, Callable, Iterator
@@ -83,8 +82,6 @@ def setup_once() -> None:
8382

8483

8584
def _capture_exception(exc: "Any") -> None:
86-
set_span_errored()
87-
8885
event, hint = event_from_exception(
8986
exc,
9087
client_options=sentry_sdk.get_client().options,
@@ -154,7 +151,7 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any":
154151
exc_info = sys.exc_info()
155152
with capture_internal_exceptions():
156153
_capture_exception(e)
157-
span.__exit__(None, None, None)
154+
span.__exit__(*exc_info)
158155
reraise(*exc_info)
159156

160157
with capture_internal_exceptions():

sentry_sdk/integrations/langchain.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from sentry_sdk.consts import OP, SPANDATA
2020
from sentry_sdk.integrations import DidNotEnable, Integration
2121
from sentry_sdk.scope import should_send_default_pii
22-
from sentry_sdk.tracing_utils import _get_value, set_span_errored
22+
from sentry_sdk.tracing_utils import _get_value
2323
from sentry_sdk.utils import capture_internal_exceptions, logger
2424

2525
if TYPE_CHECKING:
@@ -273,11 +273,10 @@ def _handle_error(self, run_id: "UUID", error: "Any") -> None:
273273

274274
span_data = self.span_map[run_id]
275275
span = span_data.span
276-
set_span_errored(span)
277276

278277
sentry_sdk.capture_exception(error, span.scope)
279278

280-
span.__exit__(None, None, None)
279+
span.__exit__(type(error), error, error.__traceback__)
281280
del self.span_map[run_id]
282281

283282
def _normalize_langchain_message(self, message: "BaseMessage") -> "Any":
@@ -1112,13 +1111,13 @@ def new_iterator() -> "Iterator[Any]":
11121111
and integration.include_prompts
11131112
):
11141113
set_data_normalized(span, SPANDATA.GEN_AI_RESPONSE_TEXT, output)
1114+
1115+
span.__exit__(None, None, None)
11151116
except Exception:
11161117
exc_info = sys.exc_info()
1117-
set_span_errored(span)
1118+
with capture_internal_exceptions():
1119+
span.__exit__(*exc_info)
11181120
raise
1119-
finally:
1120-
# Ensure cleanup happens even if iterator is abandoned or fails
1121-
span.__exit__(*exc_info)
11221121

11231122
async def new_iterator_async() -> "AsyncIterator[Any]":
11241123
exc_info: "tuple[Any, Any, Any]" = (None, None, None)
@@ -1137,13 +1136,13 @@ async def new_iterator_async() -> "AsyncIterator[Any]":
11371136
and integration.include_prompts
11381137
):
11391138
set_data_normalized(span, SPANDATA.GEN_AI_RESPONSE_TEXT, output)
1139+
1140+
span.__exit__(None, None, None)
11401141
except Exception:
11411142
exc_info = sys.exc_info()
1142-
set_span_errored(span)
1143+
with capture_internal_exceptions():
1144+
span.__exit__(*exc_info)
11431145
raise
1144-
finally:
1145-
# Ensure cleanup happens even if iterator is abandoned or fails
1146-
span.__exit__(*exc_info)
11471146

11481147
if str(type(result)) == "<class 'async_generator'>":
11491148
result = new_iterator_async()

sentry_sdk/integrations/pydantic_ai/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sentry_sdk
55
from sentry_sdk.consts import SPANDATA
66
from sentry_sdk.scope import should_send_default_pii
7-
from sentry_sdk.tracing_utils import set_span_errored
87
from sentry_sdk.utils import event_from_exception, safe_serialize
98

109
if TYPE_CHECKING:
@@ -207,8 +206,6 @@ def _set_available_tools(span: "sentry_sdk.tracing.Span", agent: "Any") -> None:
207206

208207

209208
def _capture_exception(exc: "Any", handled: bool = False) -> None:
210-
set_span_errored()
211-
212209
event, hint = event_from_exception(
213210
exc,
214211
client_options=sentry_sdk.get_client().options,

tests/integrations/cohere/test_cohere.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ def test_span_status_error(sentry_init, capture_events):
183183
assert error["level"] == "error"
184184
assert transaction["spans"][0]["status"] == "internal_error"
185185
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
186-
assert transaction["contexts"]["trace"]["status"] == "internal_error"
187186

188187

189188
@pytest.mark.parametrize(

tests/integrations/langchain/test_langchain.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,8 +2561,6 @@ def _llm_type(self) -> str:
25612561
assert transaction["spans"][0]["status"] == "internal_error"
25622562
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
25632563

2564-
assert transaction["contexts"]["trace"]["status"] == "internal_error"
2565-
25662564

25672565
def test_manual_callback_no_duplication(sentry_init):
25682566
"""

0 commit comments

Comments
 (0)