22import sys
33import weakref
44
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
710from sentry_sdk .tracing import SOURCE_FOR_STYLE
811from sentry_sdk .utils import (
912 capture_internal_exceptions ,
13+ ensure_integration_enabled ,
1014 event_from_exception ,
1115 reraise ,
1216)
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
1618
1719try :
1820 from pyramid .httpexceptions import HTTPException
1921 from pyramid .request import Request
2022except ImportError :
2123 raise DidNotEnable ("Pyramid not installed" )
2224
23- from sentry_sdk ._types import TYPE_CHECKING
2425
2526if TYPE_CHECKING :
2627 from pyramid .response import Response
@@ -73,17 +74,16 @@ def setup_once():
7374
7475 def sentry_patched_call_view (registry , request , * args , ** kwargs ):
7576 # 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 )
7878
7979 if integration is not None :
8080 _set_transaction_name_and_source (
8181 Scope .get_current_scope (), integration .transaction_style , request
8282 )
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+ )
8787
8888 return old_call_view (registry , request , * args , ** kwargs )
8989
@@ -100,7 +100,8 @@ def sentry_patched_invoke_exception_view(self, *args, **kwargs):
100100 self .exc_info
101101 and all (self .exc_info )
102102 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
104105 ):
105106 _capture_exception (self .exc_info )
106107
@@ -110,13 +111,9 @@ def sentry_patched_invoke_exception_view(self, *args, **kwargs):
110111
111112 old_wsgi_call = router .Router .__call__
112113
114+ @ensure_integration_enabled (PyramidIntegration , old_wsgi_call )
113115 def sentry_patched_wsgi_call (self , environ , start_response ):
114116 # 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-
120117 def sentry_patched_inner_wsgi_call (environ , start_response ):
121118 # type: (Dict[str, Any], Callable[..., Any]) -> Any
122119 try :
@@ -137,20 +134,18 @@ def _capture_exception(exc_info):
137134 # type: (ExcInfo) -> None
138135 if exc_info [0 ] is None or issubclass (exc_info [0 ], HTTPException ):
139136 return
140- hub = Hub .current
141- if hub .get_integration (PyramidIntegration ) is None :
142- return
143137
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
146141
147142 event , hint = event_from_exception (
148143 exc_info ,
149144 client_options = client .options ,
150145 mechanism = {"type" : "pyramid" , "handled" : False },
151146 )
152147
153- hub .capture_event (event , hint = hint )
148+ sentry_sdk .capture_event (event , hint = hint )
154149
155150
156151def _set_transaction_name_and_source (scope , transaction_style , request ):
@@ -221,7 +216,7 @@ def pyramid_event_processor(event, hint):
221216 with capture_internal_exceptions ():
222217 PyramidRequestExtractor (request ).extract_into_event (event )
223218
224- if _should_send_default_pii ():
219+ if should_send_default_pii ():
225220 with capture_internal_exceptions ():
226221 user_info = event .setdefault ("user" , {})
227222 user_info .setdefault ("id" , authenticated_userid (request ))
0 commit comments