2
2
import types
3
3
from functools import wraps
4
4
5
- from sentry_sdk .hub import Hub
6
- from sentry_sdk .utils import capture_internal_exceptions , event_from_exception , reraise
5
+ import sentry_sdk
7
6
from sentry_sdk .integrations import Integration
8
7
from sentry_sdk .integrations .logging import ignore_logger
8
+ from sentry_sdk .utils import (
9
+ capture_internal_exceptions ,
10
+ ensure_integration_enabled ,
11
+ event_from_exception ,
12
+ reraise ,
13
+ )
9
14
from sentry_sdk ._types import TYPE_CHECKING
10
15
11
16
if TYPE_CHECKING :
12
17
from typing import Any
13
18
from typing import Iterator
14
19
from typing import TypeVar
15
- from typing import Optional
16
20
from typing import Callable
17
21
18
- from sentry_sdk .client import BaseClient
19
22
from sentry_sdk ._types import ExcInfo
20
23
21
24
T = TypeVar ("T" )
@@ -113,63 +116,53 @@ def _wrap_task_call(func):
113
116
# type: (F) -> F
114
117
"""
115
118
Wrap task call with a try catch to get exceptions.
116
- Pass the client on to raise_exception so it can get rebinded.
117
119
"""
118
- client = Hub .current .client
119
120
120
121
@wraps (func )
121
122
def _inner (* args , ** kwargs ):
122
123
# type: (*Any, **Any) -> Any
123
124
try :
124
125
gen = func (* args , ** kwargs )
125
126
except Exception :
126
- raise_exception (client )
127
+ raise_exception ()
127
128
128
129
if not isinstance (gen , types .GeneratorType ):
129
130
return gen
130
- return _wrap_generator_call (gen , client )
131
+ return _wrap_generator_call (gen )
131
132
132
133
setattr (_inner , USED_FUNC , True )
133
134
return _inner # type: ignore
134
135
135
136
136
- def _capture_exception (exc_info , hub ):
137
- # type: (ExcInfo, Hub) -> None
137
+ @ensure_integration_enabled (BeamIntegration )
138
+ def _capture_exception (exc_info ):
139
+ # type: (ExcInfo) -> None
138
140
"""
139
141
Send Beam exception to Sentry.
140
142
"""
141
- integration = hub .get_integration (BeamIntegration )
142
- if integration is None :
143
- return
144
-
145
- client = hub .client
146
- if client is None :
147
- return
143
+ client = sentry_sdk .get_client ()
148
144
149
145
event , hint = event_from_exception (
150
146
exc_info ,
151
147
client_options = client .options ,
152
148
mechanism = {"type" : "beam" , "handled" : False },
153
149
)
154
- hub .capture_event (event , hint = hint )
150
+ sentry_sdk .capture_event (event , hint = hint )
155
151
156
152
157
- def raise_exception (client ):
158
- # type: (Optional[BaseClient] ) -> None
153
+ def raise_exception ():
154
+ # type: () -> None
159
155
"""
160
- Raise an exception. If the client is not in the hub, rebind it.
156
+ Raise an exception.
161
157
"""
162
- hub = Hub .current
163
- if hub .client is None :
164
- hub .bind_client (client )
165
158
exc_info = sys .exc_info ()
166
159
with capture_internal_exceptions ():
167
- _capture_exception (exc_info , hub )
160
+ _capture_exception (exc_info )
168
161
reraise (* exc_info )
169
162
170
163
171
- def _wrap_generator_call (gen , client ):
172
- # type: (Iterator[T], Optional[BaseClient] ) -> Iterator[T]
164
+ def _wrap_generator_call (gen ):
165
+ # type: (Iterator[T]) -> Iterator[T]
173
166
"""
174
167
Wrap the generator to handle any failures.
175
168
"""
@@ -179,4 +172,4 @@ def _wrap_generator_call(gen, client):
179
172
except StopIteration :
180
173
break
181
174
except Exception :
182
- raise_exception (client )
175
+ raise_exception ()
0 commit comments