Skip to content

Commit ed3ac88

Browse files
authoredJan 25, 2024
Cleaning up existing code to prepare for new Scopes API (#2611)
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.
1 parent fb03f7c commit ed3ac88

File tree

8 files changed

+666
-302
lines changed

8 files changed

+666
-302
lines changed
 

‎docs/apidocs.rst

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ API Docs
1111
.. autoclass:: sentry_sdk.Client
1212
:members:
1313

14+
.. autoclass:: sentry_sdk.client._Client
15+
:members:
16+
1417
.. autoclass:: sentry_sdk.Transport
1518
:members:
1619

‎sentry_sdk/api.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,31 @@ def capture_event(
8282
event, # type: Event
8383
hint=None, # type: Optional[Hint]
8484
scope=None, # type: Optional[Any]
85-
**scope_args # type: Any
85+
**scope_kwargs # type: Any
8686
):
8787
# type: (...) -> Optional[str]
88-
return Hub.current.capture_event(event, hint, scope=scope, **scope_args)
88+
return Hub.current.capture_event(event, hint, scope=scope, **scope_kwargs)
8989

9090

9191
@hubmethod
9292
def capture_message(
9393
message, # type: str
9494
level=None, # type: Optional[str]
9595
scope=None, # type: Optional[Any]
96-
**scope_args # type: Any
96+
**scope_kwargs # type: Any
9797
):
9898
# type: (...) -> Optional[str]
99-
return Hub.current.capture_message(message, level, scope=scope, **scope_args)
99+
return Hub.current.capture_message(message, level, scope=scope, **scope_kwargs)
100100

101101

102102
@hubmethod
103103
def capture_exception(
104104
error=None, # type: Optional[Union[BaseException, ExcInfo]]
105105
scope=None, # type: Optional[Any]
106-
**scope_args # type: Any
106+
**scope_kwargs # type: Any
107107
):
108108
# type: (...) -> Optional[str]
109-
return Hub.current.capture_exception(error, scope=scope, **scope_args)
109+
return Hub.current.capture_exception(error, scope=scope, **scope_kwargs)
110110

111111

112112
@hubmethod

‎sentry_sdk/client.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
from typing import Dict
4444
from typing import Optional
4545
from typing import Sequence
46+
from typing import Type
47+
from typing import Union
4648

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

158163
def __init__(self, *args, **kwargs):
@@ -563,8 +568,8 @@ def capture_event(
563568
564569
: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.
565570
566-
:param scope: An optional scope to use for determining whether this event
567-
should be captured.
571+
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
572+
The `scope` and `scope_kwargs` parameters are mutually exclusive.
568573
569574
: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.
570575
"""
@@ -667,6 +672,22 @@ def capture_session(
667672
else:
668673
self.session_flusher.add_session(session)
669674

675+
def get_integration(
676+
self, name_or_class # type: Union[str, Type[Integration]]
677+
):
678+
# type: (...) -> Any
679+
"""Returns the integration for this client by name or class.
680+
If the client does not have that integration then `None` is returned.
681+
"""
682+
if isinstance(name_or_class, str):
683+
integration_name = name_or_class
684+
elif name_or_class.identifier is not None:
685+
integration_name = name_or_class.identifier
686+
else:
687+
raise ValueError("Integration has no name")
688+
689+
return self.integrations.get(integration_name)
690+
670691
def close(
671692
self,
672693
timeout=None, # type: Optional[float]

0 commit comments

Comments
 (0)