3
3
import threading
4
4
from functools import wraps
5
5
6
- from sentry_sdk . hub import _should_send_default_pii , Hub
6
+ import sentry_sdk
7
7
from sentry_sdk .integrations import DidNotEnable , Integration
8
8
from sentry_sdk .integrations ._wsgi_common import _filter_headers
9
9
from sentry_sdk .integrations .asgi import SentryAsgiMiddleware
10
- from sentry_sdk .scope import Scope
10
+ from sentry_sdk .scope import Scope , should_send_default_pii
11
11
from sentry_sdk .tracing import SOURCE_FOR_STYLE
12
12
from sentry_sdk .utils import (
13
13
capture_internal_exceptions ,
14
+ ensure_integration_enabled ,
14
15
event_from_exception ,
15
16
)
16
17
from sentry_sdk ._types import TYPE_CHECKING
@@ -86,11 +87,9 @@ def patch_asgi_app():
86
87
# type: () -> None
87
88
old_app = Quart .__call__
88
89
90
+ @ensure_integration_enabled (QuartIntegration , old_app )
89
91
async def sentry_patched_asgi_app (self , scope , receive , send ):
90
92
# type: (Any, Any, Any, Any) -> Any
91
- if Hub .current .get_integration (QuartIntegration ) is None :
92
- return await old_app (self , scope , receive , send )
93
-
94
93
middleware = SentryAsgiMiddleware (lambda * a , ** kw : old_app (self , * a , ** kw ))
95
94
middleware .__call__ = middleware ._run_asgi3
96
95
return await middleware (scope , receive , send )
@@ -116,18 +115,19 @@ def decorator(old_func):
116
115
@wraps (old_func )
117
116
def _sentry_func (* args , ** kwargs ):
118
117
# type: (*Any, **Any) -> Any
119
- hub = Hub .current
120
- integration = hub .get_integration (QuartIntegration )
118
+ integration = sentry_sdk .get_client ().get_integration (
119
+ QuartIntegration
120
+ )
121
121
if integration is None :
122
122
return old_func (* args , ** kwargs )
123
123
124
- with hub . configure_scope () as sentry_scope :
125
- if sentry_scope .profile is not None :
126
- sentry_scope .profile .active_thread_id = (
127
- threading .current_thread ().ident
128
- )
124
+ scope = Scope . get_isolation_scope ()
125
+ if scope .profile is not None :
126
+ scope .profile .active_thread_id = (
127
+ threading .current_thread ().ident
128
+ )
129
129
130
- return old_func (* args , ** kwargs )
130
+ return old_func (* args , ** kwargs )
131
131
132
132
return old_decorator (_sentry_func )
133
133
@@ -156,8 +156,7 @@ def _set_transaction_name_and_source(scope, transaction_style, request):
156
156
157
157
async def _request_websocket_started (app , ** kwargs ):
158
158
# type: (Quart, **Any) -> None
159
- hub = Hub .current
160
- integration = hub .get_integration (QuartIntegration )
159
+ integration = sentry_sdk .get_client ().get_integration (QuartIntegration )
161
160
if integration is None :
162
161
return
163
162
@@ -172,11 +171,9 @@ async def _request_websocket_started(app, **kwargs):
172
171
Scope .get_current_scope (), integration .transaction_style , request_websocket
173
172
)
174
173
175
- with hub .configure_scope () as scope :
176
- evt_processor = _make_request_event_processor (
177
- app , request_websocket , integration
178
- )
179
- scope .add_event_processor (evt_processor )
174
+ scope = Scope .get_isolation_scope ()
175
+ evt_processor = _make_request_event_processor (app , request_websocket , integration )
176
+ scope .add_event_processor (evt_processor )
180
177
181
178
182
179
def _make_request_event_processor (app , request , integration ):
@@ -199,7 +196,7 @@ def inner(event, hint):
199
196
request_info ["method" ] = request .method
200
197
request_info ["headers" ] = _filter_headers (dict (request .headers ))
201
198
202
- if _should_send_default_pii ():
199
+ if should_send_default_pii ():
203
200
request_info ["env" ] = {"REMOTE_ADDR" : request .access_route [0 ]}
204
201
_add_user_to_event (event )
205
202
@@ -210,20 +207,17 @@ def inner(event, hint):
210
207
211
208
async def _capture_exception (sender , exception , ** kwargs ):
212
209
# type: (Quart, Union[ValueError, BaseException], **Any) -> None
213
- hub = Hub . current
214
- if hub .get_integration (QuartIntegration ) is None :
210
+ client = sentry_sdk . get_client ()
211
+ if client .get_integration (QuartIntegration ) is None :
215
212
return
216
213
217
- # If an integration is there, a client has to be there.
218
- client = hub .client # type: Any
219
-
220
214
event , hint = event_from_exception (
221
215
exception ,
222
216
client_options = client .options ,
223
217
mechanism = {"type" : "quart" , "handled" : False },
224
218
)
225
219
226
- hub .capture_event (event , hint = hint )
220
+ sentry_sdk .capture_event (event , hint = hint )
227
221
228
222
229
223
def _add_user_to_event (event ):
0 commit comments