Skip to content

Commit

Permalink
Revert autocomplete hack (#2224)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana authored Jul 4, 2023
1 parent 978a07f commit d8a81a9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 58 deletions.
91 changes: 63 additions & 28 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import inspect
from functools import partial

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.hub import Hub
from sentry_sdk.scope import Scope
from sentry_sdk.tracing import Transaction
from sentry_sdk.tracing import NoOpSpan, Transaction

if TYPE_CHECKING:
from typing import Any
Expand All @@ -14,8 +13,16 @@
from typing import Callable
from typing import TypeVar
from typing import ContextManager

from sentry_sdk._types import MeasurementUnit
from typing import Union

from sentry_sdk._types import (
Event,
Hint,
Breadcrumb,
BreadcrumbHint,
ExcInfo,
MeasurementUnit,
)
from sentry_sdk.tracing import Span

T = TypeVar("T")
Expand Down Expand Up @@ -70,36 +77,46 @@ def scopemethod(f):
return f


# Alias these functions to have nice auto completion for the arguments without
# having to specify them here. The `partial(..., None)` hack is needed for Sphinx
# to generate proper docs for these.
if TYPE_CHECKING:
capture_event = partial(Hub.capture_event, None)
capture_message = partial(Hub.capture_message, None)
capture_exception = partial(Hub.capture_exception, None)
add_breadcrumb = partial(Hub.add_breadcrumb, None)
start_span = partial(Hub.start_span, None)
start_transaction = partial(Hub.start_transaction, None)

else:
@hubmethod
def capture_event(
event, # type: Event
hint=None, # type: Optional[Hint]
scope=None, # type: Optional[Any]
**scope_args # type: Any
):
# type: (...) -> Optional[str]
return Hub.current.capture_event(event, hint, scope=scope, **scope_args)

def capture_event(*args, **kwargs):
return Hub.current.capture_event(*args, **kwargs)

def capture_message(*args, **kwargs):
return Hub.current.capture_message(*args, **kwargs)
@hubmethod
def capture_message(
message, # type: str
level=None, # type: Optional[str]
scope=None, # type: Optional[Any]
**scope_args # type: Any
):
# type: (...) -> Optional[str]
return Hub.current.capture_message(message, level, scope=scope, **scope_args)

def capture_exception(*args, **kwargs):
return Hub.current.capture_exception(*args, **kwargs)

def add_breadcrumb(*args, **kwargs):
return Hub.current.add_breadcrumb(*args, **kwargs)
@hubmethod
def capture_exception(
error=None, # type: Optional[Union[BaseException, ExcInfo]]
scope=None, # type: Optional[Any]
**scope_args # type: Any
):
# type: (...) -> Optional[str]
return Hub.current.capture_exception(error, scope=scope, **scope_args)

def start_span(*args, **kwargs):
return Hub.current.start_span(*args, **kwargs)

def start_transaction(*args, **kwargs):
return Hub.current.start_transaction(*args, **kwargs)
@hubmethod
def add_breadcrumb(
crumb=None, # type: Optional[Breadcrumb]
hint=None, # type: Optional[BreadcrumbHint]
**kwargs # type: Any
):
# type: (...) -> None
return Hub.current.add_breadcrumb(crumb, hint, **kwargs)


@overload
Expand Down Expand Up @@ -191,6 +208,24 @@ def last_event_id():
return Hub.current.last_event_id()


@hubmethod
def start_span(
span=None, # type: Optional[Span]
**kwargs # type: Any
):
# type: (...) -> Span
return Hub.current.start_span(span=span, **kwargs)


@hubmethod
def start_transaction(
transaction=None, # type: Optional[Transaction]
**kwargs # type: Any
):
# type: (...) -> Union[Transaction, NoOpSpan]
return Hub.current.start_transaction(transaction, **kwargs)


def set_measurement(name, value, unit=""):
# type: (str, float, MeasurementUnit) -> None
transaction = Hub.current.scope.transaction
Expand Down
32 changes: 3 additions & 29 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,48 +416,22 @@ def _capture_internal_exception(
"""
logger.error("Internal error in sentry_sdk", exc_info=exc_info)

def add_breadcrumb(
self,
crumb=None, # type: Optional[Breadcrumb]
hint=None, # type: Optional[BreadcrumbHint]
timestamp=None, # type: Optional[datetime]
type=None, # type: Optional[str]
data=None, # type: Optional[Dict[str, Any]]
**kwargs # type: Any
):
# type: (...) -> None
def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
# type: (Optional[Breadcrumb], Optional[BreadcrumbHint], Any) -> None
"""
Adds a breadcrumb.
:param crumb: Dictionary with the data as the Sentry v7/v8 protocol expects.
:param crumb: Dictionary with the data as the sentry v7/v8 protocol expects.
:param hint: An optional value that can be used by `before_breadcrumb`
to customize the breadcrumbs that are emitted.
:param timestamp: The timestamp associated with this breadcrumb. Defaults
to now if not provided.
:param type: The type of the breadcrumb. Will be set to "default" if
not provided.
:param data: Additional custom data to put on the breadcrumb.
:param kwargs: Adding any further keyword arguments will not result in
an error, but the breadcrumb will be dropped before arriving to
Sentry.
"""
client, scope = self._stack[-1]
if client is None:
logger.info("Dropped breadcrumb because no client bound")
return

crumb = dict(crumb or ()) # type: Breadcrumb
if timestamp is not None:
crumb["timestamp"] = timestamp
if type is not None:
crumb["type"] = type
if data is not None:
crumb["data"] = data
crumb.update(kwargs)
if not crumb:
return
Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,6 @@ def my_function():
@sentry_sdk.trace
async def my_async_function():
...
"""
if PY2:
from sentry_sdk.tracing_utils_py2 import start_child_span_decorator
Expand Down

0 comments on commit d8a81a9

Please sign in to comment.