1+ import sentry_sdk
12from sentry_sdk ._types import TYPE_CHECKING
2- from sentry_sdk .hub import Hub , _should_send_default_pii
33from sentry_sdk .integrations import DidNotEnable , Integration
44from sentry_sdk .integrations ._wsgi_common import RequestExtractor
55from sentry_sdk .integrations .wsgi import SentryWsgiMiddleware
6- from sentry_sdk .scope import Scope
6+ from sentry_sdk .scope import Scope , should_send_default_pii
77from sentry_sdk .tracing import SOURCE_FOR_STYLE
88from sentry_sdk .utils import (
99 capture_internal_exceptions ,
10+ ensure_integration_enabled ,
1011 event_from_exception ,
1112 package_version ,
1213)
@@ -75,11 +76,9 @@ def setup_once():
7576
7677 old_app = Flask .__call__
7778
79+ @ensure_integration_enabled (FlaskIntegration , old_app )
7880 def sentry_patched_wsgi_app (self , environ , start_response ):
7981 # type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse
80- if Hub .current .get_integration (FlaskIntegration ) is None :
81- return old_app (self , environ , start_response )
82-
8382 return SentryWsgiMiddleware (lambda * a , ** kw : old_app (self , * a , ** kw ))(
8483 environ , start_response
8584 )
@@ -92,8 +91,8 @@ def _add_sentry_trace(sender, template, context, **extra):
9291 if "sentry_trace" in context :
9392 return
9493
95- hub = Hub . current
96- trace_meta = Markup (hub .trace_propagation_meta ())
94+ scope = Scope . get_current_scope ()
95+ trace_meta = Markup (scope .trace_propagation_meta ())
9796 context ["sentry_trace" ] = trace_meta # for backwards compatibility
9897 context ["sentry_trace_meta" ] = trace_meta
9998
@@ -115,8 +114,7 @@ def _set_transaction_name_and_source(scope, transaction_style, request):
115114
116115def _request_started (app , ** kwargs ):
117116 # type: (Flask, **Any) -> None
118- hub = Hub .current
119- integration = hub .get_integration (FlaskIntegration )
117+ integration = sentry_sdk .get_client ().get_integration (FlaskIntegration )
120118 if integration is None :
121119 return
122120
@@ -128,9 +126,10 @@ def _request_started(app, **kwargs):
128126 Scope .get_current_scope (), integration .transaction_style , request
129127 )
130128
131- with hub .configure_scope () as scope :
132- evt_processor = _make_request_event_processor (app , request , integration )
133- scope .add_event_processor (evt_processor )
129+ scope = Scope .get_isolation_scope ()
130+ scope .generate_propagation_context ()
131+ evt_processor = _make_request_event_processor (app , request , integration )
132+ scope .add_event_processor (evt_processor )
134133
135134
136135class FlaskRequestExtractor (RequestExtractor ):
@@ -185,7 +184,7 @@ def inner(event, hint):
185184 with capture_internal_exceptions ():
186185 FlaskRequestExtractor (request ).extract_into_event (event )
187186
188- if _should_send_default_pii ():
187+ if should_send_default_pii ():
189188 with capture_internal_exceptions ():
190189 _add_user_to_event (event )
191190
@@ -196,20 +195,17 @@ def inner(event, hint):
196195
197196def _capture_exception (sender , exception , ** kwargs ):
198197 # type: (Flask, Union[ValueError, BaseException], **Any) -> None
199- hub = Hub . current
200- if hub .get_integration (FlaskIntegration ) is None :
198+ client = sentry_sdk . get_client ()
199+ if client .get_integration (FlaskIntegration ) is None :
201200 return
202201
203- # If an integration is there, a client has to be there.
204- client = hub .client # type: Any
205-
206202 event , hint = event_from_exception (
207203 exception ,
208204 client_options = client .options ,
209205 mechanism = {"type" : "flask" , "handled" : False },
210206 )
211207
212- hub .capture_event (event , hint = hint )
208+ sentry_sdk .capture_event (event , hint = hint )
213209
214210
215211def _add_user_to_event (event ):
0 commit comments