2
2
import sys
3
3
import weakref
4
4
5
- from sentry_sdk .hub import Hub , _should_send_default_pii
6
- from sentry_sdk .scope import Scope
5
+ import sentry_sdk
6
+ from sentry_sdk .integrations import Integration , DidNotEnable
7
+ from sentry_sdk .integrations ._wsgi_common import RequestExtractor
8
+ from sentry_sdk .integrations .wsgi import SentryWsgiMiddleware
9
+ from sentry_sdk .scope import Scope , should_send_default_pii
7
10
from sentry_sdk .tracing import SOURCE_FOR_STYLE
8
11
from sentry_sdk .utils import (
9
12
capture_internal_exceptions ,
13
+ ensure_integration_enabled ,
10
14
event_from_exception ,
11
15
reraise ,
12
16
)
13
- from sentry_sdk .integrations import Integration , DidNotEnable
14
- from sentry_sdk .integrations ._wsgi_common import RequestExtractor
15
- from sentry_sdk .integrations .wsgi import SentryWsgiMiddleware
17
+ from sentry_sdk ._types import TYPE_CHECKING
16
18
17
19
try :
18
20
from pyramid .httpexceptions import HTTPException
19
21
from pyramid .request import Request
20
22
except ImportError :
21
23
raise DidNotEnable ("Pyramid not installed" )
22
24
23
- from sentry_sdk ._types import TYPE_CHECKING
24
25
25
26
if TYPE_CHECKING :
26
27
from pyramid .response import Response
@@ -73,17 +74,16 @@ def setup_once():
73
74
74
75
def sentry_patched_call_view (registry , request , * args , ** kwargs ):
75
76
# type: (Any, Request, *Any, **Any) -> Response
76
- hub = Hub .current
77
- integration = hub .get_integration (PyramidIntegration )
77
+ integration = sentry_sdk .get_client ().get_integration (PyramidIntegration )
78
78
79
79
if integration is not None :
80
80
_set_transaction_name_and_source (
81
81
Scope .get_current_scope (), integration .transaction_style , request
82
82
)
83
- with hub . configure_scope () as scope :
84
- scope .add_event_processor (
85
- _make_event_processor (weakref .ref (request ), integration )
86
- )
83
+ scope = Scope . get_isolation_scope ()
84
+ scope .add_event_processor (
85
+ _make_event_processor (weakref .ref (request ), integration )
86
+ )
87
87
88
88
return old_call_view (registry , request , * args , ** kwargs )
89
89
@@ -100,7 +100,8 @@ def sentry_patched_invoke_exception_view(self, *args, **kwargs):
100
100
self .exc_info
101
101
and all (self .exc_info )
102
102
and rv .status_int == 500
103
- and Hub .current .get_integration (PyramidIntegration ) is not None
103
+ and sentry_sdk .get_client ().get_integration (PyramidIntegration )
104
+ is not None
104
105
):
105
106
_capture_exception (self .exc_info )
106
107
@@ -110,13 +111,9 @@ def sentry_patched_invoke_exception_view(self, *args, **kwargs):
110
111
111
112
old_wsgi_call = router .Router .__call__
112
113
114
+ @ensure_integration_enabled (PyramidIntegration , old_wsgi_call )
113
115
def sentry_patched_wsgi_call (self , environ , start_response ):
114
116
# type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse
115
- hub = Hub .current
116
- integration = hub .get_integration (PyramidIntegration )
117
- if integration is None :
118
- return old_wsgi_call (self , environ , start_response )
119
-
120
117
def sentry_patched_inner_wsgi_call (environ , start_response ):
121
118
# type: (Dict[str, Any], Callable[..., Any]) -> Any
122
119
try :
@@ -137,20 +134,18 @@ def _capture_exception(exc_info):
137
134
# type: (ExcInfo) -> None
138
135
if exc_info [0 ] is None or issubclass (exc_info [0 ], HTTPException ):
139
136
return
140
- hub = Hub .current
141
- if hub .get_integration (PyramidIntegration ) is None :
142
- return
143
137
144
- # If an integration is there, a client has to be there.
145
- client = hub .client # type: Any
138
+ client = sentry_sdk .get_client ()
139
+ if client .get_integration (PyramidIntegration ) is None :
140
+ return
146
141
147
142
event , hint = event_from_exception (
148
143
exc_info ,
149
144
client_options = client .options ,
150
145
mechanism = {"type" : "pyramid" , "handled" : False },
151
146
)
152
147
153
- hub .capture_event (event , hint = hint )
148
+ sentry_sdk .capture_event (event , hint = hint )
154
149
155
150
156
151
def _set_transaction_name_and_source (scope , transaction_style , request ):
@@ -221,7 +216,7 @@ def pyramid_event_processor(event, hint):
221
216
with capture_internal_exceptions ():
222
217
PyramidRequestExtractor (request ).extract_into_event (event )
223
218
224
- if _should_send_default_pii ():
219
+ if should_send_default_pii ():
225
220
with capture_internal_exceptions ():
226
221
user_info = event .setdefault ("user" , {})
227
222
user_info .setdefault ("id" , authenticated_userid (request ))
0 commit comments