1
- from sentry_sdk . hub import Hub
1
+ import sentry_sdk
2
2
from sentry_sdk .integrations import Integration , DidNotEnable
3
3
from sentry_sdk .integrations ._wsgi_common import RequestExtractor
4
4
from sentry_sdk .integrations .wsgi import SentryWsgiMiddleware
5
+ from sentry_sdk .scope import Scope
5
6
from sentry_sdk .tracing import SOURCE_FOR_STYLE
6
7
from sentry_sdk .utils import (
7
8
capture_internal_exceptions ,
@@ -100,14 +101,13 @@ class SentryFalconMiddleware:
100
101
101
102
def process_request (self , req , resp , * args , ** kwargs ):
102
103
# type: (Any, Any, *Any, **Any) -> None
103
- hub = Hub .current
104
- integration = hub .get_integration (FalconIntegration )
104
+ integration = sentry_sdk .get_client ().get_integration (FalconIntegration )
105
105
if integration is None :
106
106
return
107
107
108
- with hub . configure_scope () as scope :
109
- scope ._name = "falcon"
110
- scope .add_event_processor (_make_request_event_processor (req , integration ))
108
+ scope = Scope . get_isolation_scope ()
109
+ scope ._name = "falcon"
110
+ scope .add_event_processor (_make_request_event_processor (req , integration ))
111
111
112
112
113
113
TRANSACTION_STYLE_VALUES = ("uri_template" , "path" )
@@ -150,8 +150,7 @@ def _patch_wsgi_app():
150
150
151
151
def sentry_patched_wsgi_app (self , env , start_response ):
152
152
# type: (falcon.API, Any, Any) -> Any
153
- hub = Hub .current
154
- integration = hub .get_integration (FalconIntegration )
153
+ integration = sentry_sdk .get_client ().get_integration (FalconIntegration )
155
154
if integration is None :
156
155
return original_wsgi_app (self , env , start_response )
157
156
@@ -188,19 +187,17 @@ def sentry_patched_handle_exception(self, *args):
188
187
# capture_internal_exceptions block above.
189
188
return was_handled
190
189
191
- hub = Hub . current
192
- integration = hub .get_integration (FalconIntegration )
190
+ client = sentry_sdk . get_client ()
191
+ integration = client .get_integration (FalconIntegration )
193
192
194
193
if integration is not None and _exception_leads_to_http_5xx (ex , response ):
195
194
# If an integration is there, a client has to be there.
196
- client = hub .client # type: Any
197
-
198
195
event , hint = event_from_exception (
199
196
ex ,
200
197
client_options = client .options ,
201
198
mechanism = {"type" : "falcon" , "handled" : False },
202
199
)
203
- hub .capture_event (event , hint = hint )
200
+ sentry_sdk .capture_event (event , hint = hint )
204
201
205
202
return was_handled
206
203
@@ -219,8 +216,7 @@ def sentry_patched_prepare_middleware(
219
216
# We don't support ASGI Falcon apps, so we don't patch anything here
220
217
return original_prepare_middleware (middleware , independent_middleware , asgi )
221
218
222
- hub = Hub .current
223
- integration = hub .get_integration (FalconIntegration )
219
+ integration = sentry_sdk .get_client ().get_integration (FalconIntegration )
224
220
if integration is not None :
225
221
middleware = [SentryFalconMiddleware ()] + (middleware or [])
226
222
0 commit comments