diff --git a/sentry_sdk/integrations/huggingface_hub.py b/sentry_sdk/integrations/huggingface_hub.py index 8509cadefa..30d1a76f8b 100644 --- a/sentry_sdk/integrations/huggingface_hub.py +++ b/sentry_sdk/integrations/huggingface_hub.py @@ -5,10 +5,10 @@ import sentry_sdk from sentry_sdk.ai.monitoring import record_token_usage from sentry_sdk.ai.utils import set_data_normalized -from sentry_sdk.consts import OP, SPANDATA +from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS 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.tracing_utils import get_current_span from sentry_sdk.utils import ( capture_internal_exceptions, event_from_exception, @@ -53,7 +53,11 @@ def setup_once() -> None: def _capture_exception(exc: "Any") -> None: - set_span_errored() + # Only mark the current AI span as errored; do not propagate to the + # containing HTTP transaction. (fixes #5793) + span = get_current_span() + if span is not None: + span.set_status(SPANSTATUS.INTERNAL_ERROR) event, hint = event_from_exception( exc, diff --git a/tests/integrations/huggingface_hub/test_huggingface_hub.py b/tests/integrations/huggingface_hub/test_huggingface_hub.py index 851c1f717a..56447eb80d 100644 --- a/tests/integrations/huggingface_hub/test_huggingface_hub.py +++ b/tests/integrations/huggingface_hub/test_huggingface_hub.py @@ -835,7 +835,9 @@ def test_span_status_error( assert span["status"] == "internal_error" assert span["tags"]["status"] == "internal_error" - assert transaction["contexts"]["trace"]["status"] == "internal_error" + # The huggingface_hub integration must NOT set the transaction status to + # internal_error — only the inner span should be errored. (fixes #5793) + assert transaction["contexts"]["trace"]["status"] != "internal_error" @pytest.mark.httpx_mock(assert_all_requests_were_expected=False)