|
1 | 1 | import inspect
|
2 |
| -from functools import partial |
3 | 2 |
|
4 | 3 | from sentry_sdk._types import TYPE_CHECKING
|
5 | 4 | from sentry_sdk.hub import Hub
|
6 | 5 | from sentry_sdk.scope import Scope
|
7 |
| -from sentry_sdk.tracing import Transaction |
| 6 | +from sentry_sdk.tracing import NoOpSpan, Transaction |
8 | 7 |
|
9 | 8 | if TYPE_CHECKING:
|
10 | 9 | from typing import Any
|
|
14 | 13 | from typing import Callable
|
15 | 14 | from typing import TypeVar
|
16 | 15 | from typing import ContextManager
|
17 |
| - |
18 |
| - from sentry_sdk._types import MeasurementUnit |
| 16 | + from typing import Union |
| 17 | + |
| 18 | + from sentry_sdk._types import ( |
| 19 | + Event, |
| 20 | + Hint, |
| 21 | + Breadcrumb, |
| 22 | + BreadcrumbHint, |
| 23 | + ExcInfo, |
| 24 | + MeasurementUnit, |
| 25 | + ) |
19 | 26 | from sentry_sdk.tracing import Span
|
20 | 27 |
|
21 | 28 | T = TypeVar("T")
|
@@ -70,36 +77,46 @@ def scopemethod(f):
|
70 | 77 | return f
|
71 | 78 |
|
72 | 79 |
|
73 |
| -# Alias these functions to have nice auto completion for the arguments without |
74 |
| -# having to specify them here. The `partial(..., None)` hack is needed for Sphinx |
75 |
| -# to generate proper docs for these. |
76 |
| -if TYPE_CHECKING: |
77 |
| - capture_event = partial(Hub.capture_event, None) |
78 |
| - capture_message = partial(Hub.capture_message, None) |
79 |
| - capture_exception = partial(Hub.capture_exception, None) |
80 |
| - add_breadcrumb = partial(Hub.add_breadcrumb, None) |
81 |
| - start_span = partial(Hub.start_span, None) |
82 |
| - start_transaction = partial(Hub.start_transaction, None) |
83 |
| - |
84 |
| -else: |
| 80 | +@hubmethod |
| 81 | +def capture_event( |
| 82 | + event, # type: Event |
| 83 | + hint=None, # type: Optional[Hint] |
| 84 | + scope=None, # type: Optional[Any] |
| 85 | + **scope_args # type: Any |
| 86 | +): |
| 87 | + # type: (...) -> Optional[str] |
| 88 | + return Hub.current.capture_event(event, hint, scope=scope, **scope_args) |
85 | 89 |
|
86 |
| - def capture_event(*args, **kwargs): |
87 |
| - return Hub.current.capture_event(*args, **kwargs) |
88 | 90 |
|
89 |
| - def capture_message(*args, **kwargs): |
90 |
| - return Hub.current.capture_message(*args, **kwargs) |
| 91 | +@hubmethod |
| 92 | +def capture_message( |
| 93 | + message, # type: str |
| 94 | + level=None, # type: Optional[str] |
| 95 | + scope=None, # type: Optional[Any] |
| 96 | + **scope_args # type: Any |
| 97 | +): |
| 98 | + # type: (...) -> Optional[str] |
| 99 | + return Hub.current.capture_message(message, level, scope=scope, **scope_args) |
91 | 100 |
|
92 |
| - def capture_exception(*args, **kwargs): |
93 |
| - return Hub.current.capture_exception(*args, **kwargs) |
94 | 101 |
|
95 |
| - def add_breadcrumb(*args, **kwargs): |
96 |
| - return Hub.current.add_breadcrumb(*args, **kwargs) |
| 102 | +@hubmethod |
| 103 | +def capture_exception( |
| 104 | + error=None, # type: Optional[Union[BaseException, ExcInfo]] |
| 105 | + scope=None, # type: Optional[Any] |
| 106 | + **scope_args # type: Any |
| 107 | +): |
| 108 | + # type: (...) -> Optional[str] |
| 109 | + return Hub.current.capture_exception(error, scope=scope, **scope_args) |
97 | 110 |
|
98 |
| - def start_span(*args, **kwargs): |
99 |
| - return Hub.current.start_span(*args, **kwargs) |
100 | 111 |
|
101 |
| - def start_transaction(*args, **kwargs): |
102 |
| - return Hub.current.start_transaction(*args, **kwargs) |
| 112 | +@hubmethod |
| 113 | +def add_breadcrumb( |
| 114 | + crumb=None, # type: Optional[Breadcrumb] |
| 115 | + hint=None, # type: Optional[BreadcrumbHint] |
| 116 | + **kwargs # type: Any |
| 117 | +): |
| 118 | + # type: (...) -> None |
| 119 | + return Hub.current.add_breadcrumb(crumb, hint, **kwargs) |
103 | 120 |
|
104 | 121 |
|
105 | 122 | @overload
|
@@ -191,6 +208,24 @@ def last_event_id():
|
191 | 208 | return Hub.current.last_event_id()
|
192 | 209 |
|
193 | 210 |
|
| 211 | +@hubmethod |
| 212 | +def start_span( |
| 213 | + span=None, # type: Optional[Span] |
| 214 | + **kwargs # type: Any |
| 215 | +): |
| 216 | + # type: (...) -> Span |
| 217 | + return Hub.current.start_span(span=span, **kwargs) |
| 218 | + |
| 219 | + |
| 220 | +@hubmethod |
| 221 | +def start_transaction( |
| 222 | + transaction=None, # type: Optional[Transaction] |
| 223 | + **kwargs # type: Any |
| 224 | +): |
| 225 | + # type: (...) -> Union[Transaction, NoOpSpan] |
| 226 | + return Hub.current.start_transaction(transaction, **kwargs) |
| 227 | + |
| 228 | + |
194 | 229 | def set_measurement(name, value, unit=""):
|
195 | 230 | # type: (str, float, MeasurementUnit) -> None
|
196 | 231 | transaction = Hub.current.scope.transaction
|
|
0 commit comments