Skip to content

Commit 0b990da

Browse files
fix(anthropic): Stop setting transaction status when child span fails (#5717)
Stop setting the transaction status when an exception is raised, since the transaction may not be managed by the Anthropic integration.
1 parent 45abbe3 commit 0b990da

2 files changed

Lines changed: 2 additions & 7 deletions

File tree

sentry_sdk/integrations/anthropic.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from sentry_sdk.consts import OP, SPANDATA
1818
from sentry_sdk.integrations import _check_minimum_version, DidNotEnable, Integration
1919
from sentry_sdk.scope import should_send_default_pii
20-
from sentry_sdk.tracing_utils import set_span_errored
2120
from sentry_sdk.utils import (
2221
capture_internal_exceptions,
2322
event_from_exception,
@@ -195,8 +194,6 @@ def setup_once() -> None:
195194

196195

197196
def _capture_exception(exc: "Any") -> None:
198-
set_span_errored()
199-
200197
event, hint = event_from_exception(
201198
exc,
202199
client_options=sentry_sdk.get_client().options,
@@ -633,7 +630,7 @@ def _sentry_patched_create_sync(f: "Any", *args: "Any", **kwargs: "Any") -> "Any
633630
exc_info = sys.exc_info()
634631
with capture_internal_exceptions():
635632
_capture_exception(exc)
636-
span.__exit__(None, None, None)
633+
span.__exit__(*exc_info)
637634
reraise(*exc_info)
638635

639636
if isinstance(result, Stream):
@@ -721,7 +718,7 @@ async def _sentry_patched_create_async(
721718
exc_info = sys.exc_info()
722719
with capture_internal_exceptions():
723720
_capture_exception(exc)
724-
span.__exit__(None, None, None)
721+
span.__exit__(*exc_info)
725722
reraise(*exc_info)
726723

727724
if isinstance(result, AsyncStream):

tests/integrations/anthropic/test_anthropic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,6 @@ def test_span_status_error(sentry_init, capture_events):
22042204
assert error["level"] == "error"
22052205
assert transaction["spans"][0]["status"] == "internal_error"
22062206
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
2207-
assert transaction["contexts"]["trace"]["status"] == "internal_error"
22082207
assert transaction["spans"][0]["data"][SPANDATA.GEN_AI_SYSTEM] == "anthropic"
22092208
assert transaction["spans"][0]["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat"
22102209

@@ -2230,7 +2229,6 @@ async def test_span_status_error_async(sentry_init, capture_events):
22302229
assert error["level"] == "error"
22312230
assert transaction["spans"][0]["status"] == "internal_error"
22322231
assert transaction["spans"][0]["tags"]["status"] == "internal_error"
2233-
assert transaction["contexts"]["trace"]["status"] == "internal_error"
22342232
assert transaction["spans"][0]["data"][SPANDATA.GEN_AI_SYSTEM] == "anthropic"
22352233
assert transaction["spans"][0]["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat"
22362234

0 commit comments

Comments
 (0)