1- from sentry_sdk . hub import Hub
1+ import sentry_sdk
22from sentry_sdk .integrations import Integration , DidNotEnable
33from sentry_sdk .integrations ._wsgi_common import RequestExtractor
44from sentry_sdk .integrations .wsgi import SentryWsgiMiddleware
5+ from sentry_sdk .scope import Scope
56from sentry_sdk .tracing import SOURCE_FOR_STYLE
67from sentry_sdk .utils import (
78 capture_internal_exceptions ,
@@ -100,14 +101,13 @@ class SentryFalconMiddleware:
100101
101102 def process_request (self , req , resp , * args , ** kwargs ):
102103 # 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 )
105105 if integration is None :
106106 return
107107
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 ))
111111
112112
113113TRANSACTION_STYLE_VALUES = ("uri_template" , "path" )
@@ -150,8 +150,7 @@ def _patch_wsgi_app():
150150
151151 def sentry_patched_wsgi_app (self , env , start_response ):
152152 # 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 )
155154 if integration is None :
156155 return original_wsgi_app (self , env , start_response )
157156
@@ -188,19 +187,17 @@ def sentry_patched_handle_exception(self, *args):
188187 # capture_internal_exceptions block above.
189188 return was_handled
190189
191- hub = Hub . current
192- integration = hub .get_integration (FalconIntegration )
190+ client = sentry_sdk . get_client ()
191+ integration = client .get_integration (FalconIntegration )
193192
194193 if integration is not None and _exception_leads_to_http_5xx (ex , response ):
195194 # If an integration is there, a client has to be there.
196- client = hub .client # type: Any
197-
198195 event , hint = event_from_exception (
199196 ex ,
200197 client_options = client .options ,
201198 mechanism = {"type" : "falcon" , "handled" : False },
202199 )
203- hub .capture_event (event , hint = hint )
200+ sentry_sdk .capture_event (event , hint = hint )
204201
205202 return was_handled
206203
@@ -219,8 +216,7 @@ def sentry_patched_prepare_middleware(
219216 # We don't support ASGI Falcon apps, so we don't patch anything here
220217 return original_prepare_middleware (middleware , independent_middleware , asgi )
221218
222- hub = Hub .current
223- integration = hub .get_integration (FalconIntegration )
219+ integration = sentry_sdk .get_client ().get_integration (FalconIntegration )
224220 if integration is not None :
225221 middleware = [SentryFalconMiddleware ()] + (middleware or [])
226222
0 commit comments