1
1
import inspect
2
- from contextlib import contextmanager
3
2
4
3
from sentry_sdk .hub import Hub
5
4
from sentry_sdk .scope import Scope
@@ -72,10 +71,7 @@ def capture_event(
72
71
** scope_args # type: Dict[str, Any]
73
72
):
74
73
# type: (...) -> Optional[str]
75
- hub = Hub .current
76
- if hub is not None :
77
- return hub .capture_event (event , hint , scope = scope , ** scope_args )
78
- return None
74
+ return Hub .current .capture_event (event , hint , scope = scope , ** scope_args )
79
75
80
76
81
77
@hubmethod
@@ -86,10 +82,7 @@ def capture_message(
86
82
** scope_args # type: Dict[str, Any]
87
83
):
88
84
# type: (...) -> Optional[str]
89
- hub = Hub .current
90
- if hub is not None :
91
- return hub .capture_message (message , level , scope = scope , ** scope_args )
92
- return None
85
+ return Hub .current .capture_message (message , level , scope = scope , ** scope_args )
93
86
94
87
95
88
@hubmethod
@@ -99,10 +92,7 @@ def capture_exception(
99
92
** scope_args # type: Dict[str, Any]
100
93
):
101
94
# type: (...) -> Optional[str]
102
- hub = Hub .current
103
- if hub is not None :
104
- return hub .capture_exception (error , scope = scope , ** scope_args )
105
- return None
95
+ return Hub .current .capture_exception (error , scope = scope , ** scope_args )
106
96
107
97
108
98
@hubmethod
@@ -112,9 +102,7 @@ def add_breadcrumb(
112
102
** kwargs # type: Any
113
103
):
114
104
# type: (...) -> None
115
- hub = Hub .current
116
- if hub is not None :
117
- return hub .add_breadcrumb (crumb , hint , ** kwargs )
105
+ return Hub .current .add_breadcrumb (crumb , hint , ** kwargs )
118
106
119
107
120
108
@overload # noqa
@@ -136,19 +124,7 @@ def configure_scope(
136
124
callback = None , # type: Optional[Callable[[Scope], None]]
137
125
):
138
126
# type: (...) -> Optional[ContextManager[Scope]]
139
- hub = Hub .current
140
- if hub is not None :
141
- return hub .configure_scope (callback )
142
- elif callback is None :
143
-
144
- @contextmanager
145
- def inner ():
146
- yield Scope ()
147
-
148
- return inner ()
149
- else :
150
- # returned if user provided callback
151
- return None
127
+ return Hub .current .configure_scope (callback )
152
128
153
129
154
130
@overload # noqa
@@ -170,59 +146,37 @@ def push_scope(
170
146
callback = None , # type: Optional[Callable[[Scope], None]]
171
147
):
172
148
# type: (...) -> Optional[ContextManager[Scope]]
173
- hub = Hub .current
174
- if hub is not None :
175
- return hub .push_scope (callback )
176
- elif callback is None :
177
-
178
- @contextmanager
179
- def inner ():
180
- yield Scope ()
181
-
182
- return inner ()
183
- else :
184
- # returned if user provided callback
185
- return None
149
+ return Hub .current .push_scope (callback )
186
150
187
151
188
152
@scopemethod # noqa
189
153
def set_tag (key , value ):
190
154
# type: (str, Any) -> None
191
- hub = Hub .current
192
- if hub is not None :
193
- hub .scope .set_tag (key , value )
155
+ return Hub .current .scope .set_tag (key , value )
194
156
195
157
196
158
@scopemethod # noqa
197
159
def set_context (key , value ):
198
160
# type: (str, Any) -> None
199
- hub = Hub .current
200
- if hub is not None :
201
- hub .scope .set_context (key , value )
161
+ return Hub .current .scope .set_context (key , value )
202
162
203
163
204
164
@scopemethod # noqa
205
165
def set_extra (key , value ):
206
166
# type: (str, Any) -> None
207
- hub = Hub .current
208
- if hub is not None :
209
- hub .scope .set_extra (key , value )
167
+ return Hub .current .scope .set_extra (key , value )
210
168
211
169
212
170
@scopemethod # noqa
213
171
def set_user (value ):
214
172
# type: (Dict[str, Any]) -> None
215
- hub = Hub .current
216
- if hub is not None :
217
- hub .scope .set_user (value )
173
+ return Hub .current .scope .set_user (value )
218
174
219
175
220
176
@scopemethod # noqa
221
177
def set_level (value ):
222
178
# type: (str) -> None
223
- hub = Hub .current
224
- if hub is not None :
225
- hub .scope .set_level (value )
179
+ return Hub .current .scope .set_level (value )
226
180
227
181
228
182
@hubmethod
@@ -231,18 +185,13 @@ def flush(
231
185
callback = None , # type: Optional[Callable[[int, float], None]]
232
186
):
233
187
# type: (...) -> None
234
- hub = Hub .current
235
- if hub is not None :
236
- return hub .flush (timeout = timeout , callback = callback )
188
+ return Hub .current .flush (timeout = timeout , callback = callback )
237
189
238
190
239
191
@hubmethod
240
192
def last_event_id ():
241
193
# type: () -> Optional[str]
242
- hub = Hub .current
243
- if hub is not None :
244
- return hub .last_event_id ()
245
- return None
194
+ return Hub .current .last_event_id ()
246
195
247
196
248
197
@hubmethod
@@ -251,7 +200,4 @@ def start_span(
251
200
** kwargs # type: Any
252
201
):
253
202
# type: (...) -> Span
254
-
255
- # TODO: All other functions in this module check for
256
- # `Hub.current is None`. That actually should never happen?
257
203
return Hub .current .start_span (span = span , ** kwargs )
0 commit comments