@@ -63,24 +63,33 @@ def __init__(self, transaction_style="route_name"):
6363 @staticmethod
6464 def setup_once ():
6565 # type: () -> None
66- from pyramid . router import Router
66+ from pyramid import router
6767 from pyramid .request import Request
6868
69- old_handle_request = Router . handle_request
69+ old_call_view = router . _call_view
7070
71- def sentry_patched_handle_request ( self , request , * args , ** kwargs ):
71+ def sentry_patched_call_view ( registry , request , * args , ** kwargs ):
7272 # type: (Any, Request, *Any, **Any) -> Response
7373 hub = Hub .current
7474 integration = hub .get_integration (PyramidIntegration )
75+
7576 if integration is not None :
7677 with hub .configure_scope () as scope :
78+ try :
79+ if integration .transaction_style == "route_name" :
80+ scope .transaction = request .matched_route .name
81+ elif integration .transaction_style == "route_pattern" :
82+ scope .transaction = request .matched_route .pattern
83+ except Exception :
84+ raise
85+
7786 scope .add_event_processor (
7887 _make_event_processor (weakref .ref (request ), integration )
7988 )
8089
81- return old_handle_request ( self , request , * args , ** kwargs )
90+ return old_call_view ( registry , request , * args , ** kwargs )
8291
83- Router . handle_request = sentry_patched_handle_request
92+ router . _call_view = sentry_patched_call_view
8493
8594 if hasattr (Request , "invoke_exception_view" ):
8695 old_invoke_exception_view = Request .invoke_exception_view
@@ -101,7 +110,7 @@ def sentry_patched_invoke_exception_view(self, *args, **kwargs):
101110
102111 Request .invoke_exception_view = sentry_patched_invoke_exception_view
103112
104- old_wsgi_call = Router .__call__
113+ old_wsgi_call = router . Router .__call__
105114
106115 def sentry_patched_wsgi_call (self , environ , start_response ):
107116 # type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse
@@ -123,7 +132,7 @@ def sentry_patched_inner_wsgi_call(environ, start_response):
123132 environ , start_response
124133 )
125134
126- Router .__call__ = sentry_patched_wsgi_call
135+ router . Router .__call__ = sentry_patched_wsgi_call
127136
128137
129138def _capture_exception (exc_info ):
@@ -196,14 +205,6 @@ def event_processor(event, hint):
196205 if request is None :
197206 return event
198207
199- try :
200- if integration .transaction_style == "route_name" :
201- event ["transaction" ] = request .matched_route .name
202- elif integration .transaction_style == "route_pattern" :
203- event ["transaction" ] = request .matched_route .pattern
204- except Exception :
205- pass
206-
207208 with capture_internal_exceptions ():
208209 PyramidRequestExtractor (request ).extract_into_event (event )
209210
0 commit comments