Skip to content
Merged
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
10 changes: 7 additions & 3 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Optional
from typing import overload
from typing import Callable
from typing import Dict
from contextlib import ContextManager
else:

Expand All @@ -35,9 +36,11 @@ def hubmethod(f):

@hubmethod
def capture_event(event, hint=None):
# type: (Dict[str, Any], Dict[str, Any]) -> Optional[str]
hub = Hub.current
if hub is not None:
return hub.capture_event(event, hint)
return None


@hubmethod
Expand All @@ -51,18 +54,19 @@ def capture_message(message, level=None):

@hubmethod
def capture_exception(error=None):
# type: (ValueError) -> Optional[str]
# type: (Optional[BaseException]) -> Optional[str]
hub = Hub.current
if hub is not None:
return hub.capture_exception(error)
return None


@hubmethod
def add_breadcrumb(*args, **kwargs):
def add_breadcrumb(crumb=None, hint=None, **kwargs):
# type: (Dict[str, Any], Dict[str, Any], **Any) -> None
hub = Hub.current
if hub is not None:
return hub.add_breadcrumb(*args, **kwargs)
return hub.add_breadcrumb(crumb, hint, **kwargs)


@overload # noqa
Expand Down
6 changes: 5 additions & 1 deletion sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def client(self):
return self._stack[-1][0]

def last_event_id(self):
# type: () -> Optional[str]
"""Returns the last event ID."""
return self._last_event_id

Expand Down Expand Up @@ -278,6 +279,7 @@ def capture_message(self, message, level=None):
return self.capture_event({"message": message, "level": level})

def capture_exception(self, error=None):
# type: (Optional[BaseException]) -> Optional[str]
"""Captures an exception.

The argument passed can be `None` in which case the last exception
Expand All @@ -286,7 +288,7 @@ def capture_exception(self, error=None):
"""
client = self.client
if client is None:
return
return None
if error is None:
exc_info = sys.exc_info()
else:
Expand All @@ -298,6 +300,8 @@ def capture_exception(self, error=None):
except Exception:
self._capture_internal_exception(sys.exc_info())

return None

def _capture_internal_exception(self, exc_info):
"""Capture an exception that is likely caused by a bug in the SDK
itself."""
Expand Down