@@ -63,24 +63,33 @@ def __init__(self, transaction_style="route_name"):
63
63
@staticmethod
64
64
def setup_once ():
65
65
# type: () -> None
66
- from pyramid . router import Router
66
+ from pyramid import router
67
67
from pyramid .request import Request
68
68
69
- old_handle_request = Router . handle_request
69
+ old_call_view = router . _call_view
70
70
71
- def sentry_patched_handle_request ( self , request , * args , ** kwargs ):
71
+ def sentry_patched_call_view ( registry , request , * args , ** kwargs ):
72
72
# type: (Any, Request, *Any, **Any) -> Response
73
73
hub = Hub .current
74
74
integration = hub .get_integration (PyramidIntegration )
75
+
75
76
if integration is not None :
76
77
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
+
77
86
scope .add_event_processor (
78
87
_make_event_processor (weakref .ref (request ), integration )
79
88
)
80
89
81
- return old_handle_request ( self , request , * args , ** kwargs )
90
+ return old_call_view ( registry , request , * args , ** kwargs )
82
91
83
- Router . handle_request = sentry_patched_handle_request
92
+ router . _call_view = sentry_patched_call_view
84
93
85
94
if hasattr (Request , "invoke_exception_view" ):
86
95
old_invoke_exception_view = Request .invoke_exception_view
@@ -101,7 +110,7 @@ def sentry_patched_invoke_exception_view(self, *args, **kwargs):
101
110
102
111
Request .invoke_exception_view = sentry_patched_invoke_exception_view
103
112
104
- old_wsgi_call = Router .__call__
113
+ old_wsgi_call = router . Router .__call__
105
114
106
115
def sentry_patched_wsgi_call (self , environ , start_response ):
107
116
# type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse
@@ -123,7 +132,7 @@ def sentry_patched_inner_wsgi_call(environ, start_response):
123
132
environ , start_response
124
133
)
125
134
126
- Router .__call__ = sentry_patched_wsgi_call
135
+ router . Router .__call__ = sentry_patched_wsgi_call
127
136
128
137
129
138
def _capture_exception (exc_info ):
@@ -196,14 +205,6 @@ def event_processor(event, hint):
196
205
if request is None :
197
206
return event
198
207
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
-
207
208
with capture_internal_exceptions ():
208
209
PyramidRequestExtractor (request ).extract_into_event (event )
209
210
0 commit comments