1
+ import sentry_sdk
1
2
from sentry_sdk ._types import TYPE_CHECKING
2
- from sentry_sdk .hub import Hub , _should_send_default_pii
3
3
from sentry_sdk .integrations import DidNotEnable , Integration
4
4
from sentry_sdk .integrations ._wsgi_common import RequestExtractor
5
5
from sentry_sdk .integrations .wsgi import SentryWsgiMiddleware
6
- from sentry_sdk .scope import Scope
6
+ from sentry_sdk .scope import Scope , should_send_default_pii
7
7
from sentry_sdk .tracing import SOURCE_FOR_STYLE
8
8
from sentry_sdk .utils import (
9
9
capture_internal_exceptions ,
10
+ ensure_integration_enabled ,
10
11
event_from_exception ,
11
12
package_version ,
12
13
)
@@ -75,11 +76,9 @@ def setup_once():
75
76
76
77
old_app = Flask .__call__
77
78
79
+ @ensure_integration_enabled (FlaskIntegration , old_app )
78
80
def sentry_patched_wsgi_app (self , environ , start_response ):
79
81
# 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
-
83
82
return SentryWsgiMiddleware (lambda * a , ** kw : old_app (self , * a , ** kw ))(
84
83
environ , start_response
85
84
)
@@ -92,8 +91,8 @@ def _add_sentry_trace(sender, template, context, **extra):
92
91
if "sentry_trace" in context :
93
92
return
94
93
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 ())
97
96
context ["sentry_trace" ] = trace_meta # for backwards compatibility
98
97
context ["sentry_trace_meta" ] = trace_meta
99
98
@@ -115,8 +114,7 @@ def _set_transaction_name_and_source(scope, transaction_style, request):
115
114
116
115
def _request_started (app , ** kwargs ):
117
116
# type: (Flask, **Any) -> None
118
- hub = Hub .current
119
- integration = hub .get_integration (FlaskIntegration )
117
+ integration = sentry_sdk .get_client ().get_integration (FlaskIntegration )
120
118
if integration is None :
121
119
return
122
120
@@ -128,9 +126,10 @@ def _request_started(app, **kwargs):
128
126
Scope .get_current_scope (), integration .transaction_style , request
129
127
)
130
128
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 )
134
133
135
134
136
135
class FlaskRequestExtractor (RequestExtractor ):
@@ -185,7 +184,7 @@ def inner(event, hint):
185
184
with capture_internal_exceptions ():
186
185
FlaskRequestExtractor (request ).extract_into_event (event )
187
186
188
- if _should_send_default_pii ():
187
+ if should_send_default_pii ():
189
188
with capture_internal_exceptions ():
190
189
_add_user_to_event (event )
191
190
@@ -196,20 +195,17 @@ def inner(event, hint):
196
195
197
196
def _capture_exception (sender , exception , ** kwargs ):
198
197
# 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 :
201
200
return
202
201
203
- # If an integration is there, a client has to be there.
204
- client = hub .client # type: Any
205
-
206
202
event , hint = event_from_exception (
207
203
exception ,
208
204
client_options = client .options ,
209
205
mechanism = {"type" : "flask" , "handled" : False },
210
206
)
211
207
212
- hub .capture_event (event , hint = hint )
208
+ sentry_sdk .capture_event (event , hint = hint )
213
209
214
210
215
211
def _add_user_to_event (event ):
0 commit comments