Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions sentry_sdk/integrations/huggingface_hub.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -52,9 +50,9 @@ def setup_once() -> None:
)


def _capture_exception(exc: "Any") -> None:
set_span_errored()

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,
Expand Down Expand Up @@ -130,7 +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)
_capture_exception(e, span)
span.__exit__(None, None, None)
reraise(*exc_info)

Expand Down
11 changes: 4 additions & 7 deletions tests/integrations/huggingface_hub/test_huggingface_hub.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])
Expand Down