Skip to content

Commit

Permalink
Cleaning up existing code to prepare for new Scopes API (#2611)
Browse files Browse the repository at this point in the history
This cleans up existing code and reorganizes it to have a clean foundation for the refactoring the Hub and Scopes. It moves functionality away from the Hub into the Scope respectively the Client.
  • Loading branch information
antonpirker committed Jan 25, 2024
1 parent fb03f7c commit ed3ac88
Show file tree
Hide file tree
Showing 8 changed files with 666 additions and 302 deletions.
3 changes: 3 additions & 0 deletions docs/apidocs.rst
Expand Up @@ -11,6 +11,9 @@ API Docs
.. autoclass:: sentry_sdk.Client
:members:

.. autoclass:: sentry_sdk.client._Client
:members:

.. autoclass:: sentry_sdk.Transport
:members:

Expand Down
12 changes: 6 additions & 6 deletions sentry_sdk/api.py
Expand Up @@ -82,31 +82,31 @@ def capture_event(
event, # type: Event
hint=None, # type: Optional[Hint]
scope=None, # type: Optional[Any]
**scope_args # type: Any
**scope_kwargs # type: Any
):
# type: (...) -> Optional[str]
return Hub.current.capture_event(event, hint, scope=scope, **scope_args)
return Hub.current.capture_event(event, hint, scope=scope, **scope_kwargs)


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


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


@hubmethod
Expand Down
25 changes: 23 additions & 2 deletions sentry_sdk/client.py
Expand Up @@ -43,7 +43,10 @@
from typing import Dict
from typing import Optional
from typing import Sequence
from typing import Type
from typing import Union

from sentry_sdk.integrations import Integration
from sentry_sdk.scope import Scope
from sentry_sdk._types import Event, Hint
from sentry_sdk.session import Session
Expand Down Expand Up @@ -153,6 +156,8 @@ class _Client(object):
forwarding them to sentry through the configured transport. It takes
the client options as keyword arguments and optionally the DSN as first
argument.
Alias of :py:class:`Client`. (Was created for better intelisense support)
"""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -563,8 +568,8 @@ def capture_event(
:param hint: Contains metadata about the event that can be read from `before_send`, such as the original exception object or a HTTP request object.
:param scope: An optional scope to use for determining whether this event
should be captured.
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
The `scope` and `scope_kwargs` parameters are mutually exclusive.
:returns: An event ID. May be `None` if there is no DSN set or of if the SDK decided to discard the event for other reasons. In such situations setting `debug=True` on `init()` may help.
"""
Expand Down Expand Up @@ -667,6 +672,22 @@ def capture_session(
else:
self.session_flusher.add_session(session)

def get_integration(
self, name_or_class # type: Union[str, Type[Integration]]
):
# type: (...) -> Any
"""Returns the integration for this client by name or class.
If the client does not have that integration then `None` is returned.
"""
if isinstance(name_or_class, str):
integration_name = name_or_class
elif name_or_class.identifier is not None:
integration_name = name_or_class.identifier
else:
raise ValueError("Integration has no name")

return self.integrations.get(integration_name)

def close(
self,
timeout=None, # type: Optional[float]
Expand Down

0 comments on commit ed3ac88

Please sign in to comment.