diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index ee9682343a..657b697052 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -63,24 +63,33 @@ def __init__(self, transaction_style="route_name"): @staticmethod def setup_once(): # type: () -> None - from pyramid.router import Router + from pyramid import router from pyramid.request import Request - old_handle_request = Router.handle_request + old_call_view = router._call_view - def sentry_patched_handle_request(self, request, *args, **kwargs): + def sentry_patched_call_view(registry, request, *args, **kwargs): # type: (Any, Request, *Any, **Any) -> Response hub = Hub.current integration = hub.get_integration(PyramidIntegration) + if integration is not None: with hub.configure_scope() as scope: + try: + if integration.transaction_style == "route_name": + scope.transaction = request.matched_route.name + elif integration.transaction_style == "route_pattern": + scope.transaction = request.matched_route.pattern + except Exception: + raise + scope.add_event_processor( _make_event_processor(weakref.ref(request), integration) ) - return old_handle_request(self, request, *args, **kwargs) + return old_call_view(registry, request, *args, **kwargs) - Router.handle_request = sentry_patched_handle_request + router._call_view = sentry_patched_call_view if hasattr(Request, "invoke_exception_view"): old_invoke_exception_view = Request.invoke_exception_view @@ -101,7 +110,7 @@ def sentry_patched_invoke_exception_view(self, *args, **kwargs): Request.invoke_exception_view = sentry_patched_invoke_exception_view - old_wsgi_call = Router.__call__ + old_wsgi_call = router.Router.__call__ def sentry_patched_wsgi_call(self, environ, start_response): # type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse @@ -123,7 +132,7 @@ def sentry_patched_inner_wsgi_call(environ, start_response): environ, start_response ) - Router.__call__ = sentry_patched_wsgi_call + router.Router.__call__ = sentry_patched_wsgi_call def _capture_exception(exc_info): @@ -196,14 +205,6 @@ def event_processor(event, hint): if request is None: return event - try: - if integration.transaction_style == "route_name": - event["transaction"] = request.matched_route.name - elif integration.transaction_style == "route_pattern": - event["transaction"] = request.matched_route.pattern - except Exception: - pass - with capture_internal_exceptions(): PyramidRequestExtractor(request).extract_into_event(event) diff --git a/tox.ini b/tox.ini index 67e957d2ae..7fdba0dacb 100644 --- a/tox.ini +++ b/tox.ini @@ -44,7 +44,7 @@ envlist = # The aws_lambda tests deploy to the real AWS and have their own matrix of Python versions. py3.7-aws_lambda - {pypy,py2.7,py3.5,py3.6,py3.7,py3.8}-pyramid-{1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.10} + {pypy,py2.7,py3.5,py3.6,py3.7,py3.8}-pyramid-{1.6,1.7,1.8,1.9,1.10} {pypy,py2.7,py3.5,py3.6}-rq-{0.6,0.7,0.8,0.9,0.10,0.11} {pypy,py2.7,py3.5,py3.6,py3.7,py3.8}-rq-{0.12,0.13,1.0,1.1,1.2,1.3} @@ -127,9 +127,6 @@ deps = aws_lambda: boto3 - pyramid-1.3: pyramid>=1.3,<1.4 - pyramid-1.4: pyramid>=1.4,<1.5 - pyramid-1.5: pyramid>=1.5,<1.6 pyramid-1.6: pyramid>=1.6,<1.7 pyramid-1.7: pyramid>=1.7,<1.8 pyramid-1.8: pyramid>=1.8,<1.9