From 0e66448da835fed104d8825eb63ddb2906797306 Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 7 Apr 2026 14:10:13 -0400 Subject: [PATCH 1/2] huggingface_hub: stop setting http transaction status on AI errors --- sentry_sdk/integrations/huggingface_hub.py | 11 ++++------- .../huggingface_hub/test_huggingface_hub.py | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/sentry_sdk/integrations/huggingface_hub.py b/sentry_sdk/integrations/huggingface_hub.py index 733715621d..e26e6d396f 100644 --- a/sentry_sdk/integrations/huggingface_hub.py +++ b/sentry_sdk/integrations/huggingface_hub.py @@ -1,22 +1,20 @@ -import sys import inspect +import sys from functools import wraps +from typing import TYPE_CHECKING 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.utils import ( capture_internal_exceptions, event_from_exception, reraise, ) -from typing import TYPE_CHECKING - if TYPE_CHECKING: from typing import Any, Callable, Iterable @@ -53,8 +51,6 @@ def setup_once() -> None: def _capture_exception(exc: "Any") -> None: - set_span_errored() - event, hint = event_from_exception( exc, client_options=sentry_sdk.get_client().options, @@ -131,6 +127,7 @@ def new_huggingface_task(*args: "Any", **kwargs: "Any") -> "Any": exc_info = sys.exc_info() with capture_internal_exceptions(): _capture_exception(e) + span.set_status(SPANSTATUS.INTERNAL_ERROR) span.__exit__(None, None, None) reraise(*exc_info) diff --git a/tests/integrations/huggingface_hub/test_huggingface_hub.py b/tests/integrations/huggingface_hub/test_huggingface_hub.py index e4cf6e9dcc..9dd15ca4b5 100644 --- a/tests/integrations/huggingface_hub/test_huggingface_hub.py +++ b/tests/integrations/huggingface_hub/test_huggingface_hub.py @@ -1,15 +1,14 @@ +import re +from typing import TYPE_CHECKING from unittest import mock + import pytest -import re import responses - from huggingface_hub import InferenceClient import sentry_sdk -from sentry_sdk.utils import package_version from sentry_sdk.integrations.huggingface_hub import HuggingfaceHubIntegration - -from typing import TYPE_CHECKING +from sentry_sdk.utils import package_version try: from huggingface_hub.utils._errors import HfHubHTTPError @@ -834,8 +833,6 @@ def test_span_status_error( assert span["status"] == "internal_error" assert span["tags"]["status"] == "internal_error" - assert transaction["contexts"]["trace"]["status"] == "internal_error" - @pytest.mark.httpx_mock(assert_all_requests_were_expected=False) @pytest.mark.parametrize("send_default_pii", [True, False]) From 945cd94ec989e7610c34a01dad26e00689ac758c Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 8 Apr 2026 14:26:31 -0400 Subject: [PATCH 2/2] move setting span to _capture_exception --- sentry_sdk/integrations/huggingface_hub.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/huggingface_hub.py b/sentry_sdk/integrations/huggingface_hub.py index e26e6d396f..83a338527f 100644 --- a/sentry_sdk/integrations/huggingface_hub.py +++ b/sentry_sdk/integrations/huggingface_hub.py @@ -50,7 +50,9 @@ def setup_once() -> None: ) -def _capture_exception(exc: "Any") -> None: +def _capture_exception(exc: "Any", span: "Any" = None) -> None: + if span is not None: + span.set_status(SPANSTATUS.INTERNAL_ERROR) event, hint = event_from_exception( exc, client_options=sentry_sdk.get_client().options, @@ -126,8 +128,7 @@ def new_huggingface_task(*args: "Any", **kwargs: "Any") -> "Any": except Exception as e: exc_info = sys.exc_info() with capture_internal_exceptions(): - _capture_exception(e) - span.set_status(SPANSTATUS.INTERNAL_ERROR) + _capture_exception(e, span) span.__exit__(None, None, None) reraise(*exc_info)