We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Setting transaction name in pyramid
Hi is it possible to set transaction name when using PyramidIntegration?
I tried setting `scope.transaction = "mycustomname"` but it seems that integration itself does:

        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

And I suspect that overwrites anything I've set up earlier?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sentry_sdk/integrations/pyramid.py`
Content:
```
1 from __future__ import absolute_import
2 
3 import os
4 import sys
5 import weakref
6 
7 from pyramid.httpexceptions import HTTPException
8 from pyramid.request import Request
9 
10 from sentry_sdk.hub import Hub, _should_send_default_pii
11 from sentry_sdk.utils import capture_internal_exceptions, event_from_exception
12 from sentry_sdk._compat import reraise, iteritems
13 
14 from sentry_sdk.integrations import Integration
15 from sentry_sdk.integrations._wsgi_common import RequestExtractor
16 from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
17 
18 from sentry_sdk._types import MYPY
19 
20 if MYPY:
21     from pyramid.response import Response
22     from typing import Any
23     from sentry_sdk.integrations.wsgi import _ScopedResponse
24     from typing import Callable
25     from typing import Dict
26     from typing import Optional
27     from webob.cookies import RequestCookies  # type: ignore
28     from webob.compat import cgi_FieldStorage  # type: ignore
29 
30     from sentry_sdk.utils import ExcInfo
31     from sentry_sdk._types import EventProcessor
32 
33 
34 if getattr(Request, "authenticated_userid", None):
35 
36     def authenticated_userid(request):
37         # type: (Request) -> Optional[Any]
38         return request.authenticated_userid
39 
40 
41 else:
42     # bw-compat for pyramid < 1.5
43     from pyramid.security import authenticated_userid  # type: ignore
44 
45 
46 TRANSACTION_STYLE_VALUES = ("route_name", "route_pattern")
47 
48 
49 class PyramidIntegration(Integration):
50     identifier = "pyramid"
51 
52     transaction_style = None
53 
54     def __init__(self, transaction_style="route_name"):
55         # type: (str) -> None
56         if transaction_style not in TRANSACTION_STYLE_VALUES:
57             raise ValueError(
58                 "Invalid value for transaction_style: %s (must be in %s)"
59                 % (transaction_style, TRANSACTION_STYLE_VALUES)
60             )
61         self.transaction_style = transaction_style
62 
63     @staticmethod
64     def setup_once():
65         # type: () -> None
66         from pyramid.router import Router
67         from pyramid.request import Request
68 
69         old_handle_request = Router.handle_request
70 
71         def sentry_patched_handle_request(self, request, *args, **kwargs):
72             # type: (Any, Request, *Any, **Any) -> Response
73             hub = Hub.current
74             integration = hub.get_integration(PyramidIntegration)
75             if integration is not None:
76                 with hub.configure_scope() as scope:
77                     scope.add_event_processor(
78                         _make_event_processor(weakref.ref(request), integration)
79                     )
80 
81             return old_handle_request(self, request, *args, **kwargs)
82 
83         Router.handle_request = sentry_patched_handle_request
84 
85         if hasattr(Request, "invoke_exception_view"):
86             old_invoke_exception_view = Request.invoke_exception_view
87 
88             def sentry_patched_invoke_exception_view(self, *args, **kwargs):
89                 # type: (Request, *Any, **Any) -> Any
90                 rv = old_invoke_exception_view(self, *args, **kwargs)
91 
92                 if (
93                     self.exc_info
94                     and all(self.exc_info)
95                     and rv.status_int == 500
96                     and Hub.current.get_integration(PyramidIntegration) is not None
97                 ):
98                     _capture_exception(self.exc_info)
99 
100                 return rv
101 
102             Request.invoke_exception_view = sentry_patched_invoke_exception_view
103 
104         old_wsgi_call = Router.__call__
105 
106         def sentry_patched_wsgi_call(self, environ, start_response):
107             # type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse
108             hub = Hub.current
109             integration = hub.get_integration(PyramidIntegration)
110             if integration is None:
111                 return old_wsgi_call(self, environ, start_response)
112 
113             def sentry_patched_inner_wsgi_call(environ, start_response):
114                 # type: (Dict[str, Any], Callable[..., Any]) -> Any
115                 try:
116                     return old_wsgi_call(self, environ, start_response)
117                 except Exception:
118                     einfo = sys.exc_info()
119                     _capture_exception(einfo)
120                     reraise(*einfo)
121 
122             return SentryWsgiMiddleware(sentry_patched_inner_wsgi_call)(
123                 environ, start_response
124             )
125 
126         Router.__call__ = sentry_patched_wsgi_call
127 
128 
129 def _capture_exception(exc_info):
130     # type: (ExcInfo) -> None
131     if exc_info[0] is None or issubclass(exc_info[0], HTTPException):
132         return
133     hub = Hub.current
134     if hub.get_integration(PyramidIntegration) is None:
135         return
136 
137     # If an integration is there, a client has to be there.
138     client = hub.client  # type: Any
139 
140     event, hint = event_from_exception(
141         exc_info,
142         client_options=client.options,
143         mechanism={"type": "pyramid", "handled": False},
144     )
145 
146     hub.capture_event(event, hint=hint)
147 
148 
149 class PyramidRequestExtractor(RequestExtractor):
150     def url(self):
151         # type: () -> str
152         return self.request.path_url
153 
154     def env(self):
155         # type: () -> Dict[str, str]
156         return self.request.environ
157 
158     def cookies(self):
159         # type: () -> RequestCookies
160         return self.request.cookies
161 
162     def raw_data(self):
163         # type: () -> str
164         return self.request.text
165 
166     def form(self):
167         # type: () -> Dict[str, str]
168         return {
169             key: value
170             for key, value in iteritems(self.request.POST)
171             if not getattr(value, "filename", None)
172         }
173 
174     def files(self):
175         # type: () -> Dict[str, cgi_FieldStorage]
176         return {
177             key: value
178             for key, value in iteritems(self.request.POST)
179             if getattr(value, "filename", None)
180         }
181 
182     def size_of_file(self, postdata):
183         # type: (cgi_FieldStorage) -> int
184         file = postdata.file
185         try:
186             return os.fstat(file.fileno()).st_size
187         except Exception:
188             return 0
189 
190 
191 def _make_event_processor(weak_request, integration):
192     # type: (Callable[[], Request], PyramidIntegration) -> EventProcessor
193     def event_processor(event, hint):
194         # type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any]
195         request = weak_request()
196         if request is None:
197             return event
198 
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         with capture_internal_exceptions():
208             PyramidRequestExtractor(request).extract_into_event(event)
209 
210         if _should_send_default_pii():
211             with capture_internal_exceptions():
212                 user_info = event.setdefault("user", {})
213                 user_info.setdefault("id", authenticated_userid(request))
214 
215         return event
216 
217     return event_processor
218
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py
--- a/sentry_sdk/integrations/pyramid.py
+++ b/sentry_sdk/integrations/pyramid.py
@@ -63,24 +63,33 @@
     @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 @@
 
             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 @@
                 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 @@
         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)

{"golden_diff": "diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py\n--- a/sentry_sdk/integrations/pyramid.py\n+++ b/sentry_sdk/integrations/pyramid.py\n@@ -63,24 +63,33 @@\n     @staticmethod\n     def setup_once():\n         # type: () -> None\n-        from pyramid.router import Router\n+        from pyramid import router\n         from pyramid.request import Request\n \n-        old_handle_request = Router.handle_request\n+        old_call_view = router._call_view\n \n-        def sentry_patched_handle_request(self, request, *args, **kwargs):\n+        def sentry_patched_call_view(registry, request, *args, **kwargs):\n             # type: (Any, Request, *Any, **Any) -> Response\n             hub = Hub.current\n             integration = hub.get_integration(PyramidIntegration)\n+\n             if integration is not None:\n                 with hub.configure_scope() as scope:\n+                    try:\n+                        if integration.transaction_style == \"route_name\":\n+                            scope.transaction = request.matched_route.name\n+                        elif integration.transaction_style == \"route_pattern\":\n+                            scope.transaction = request.matched_route.pattern\n+                    except Exception:\n+                        raise\n+\n                     scope.add_event_processor(\n                         _make_event_processor(weakref.ref(request), integration)\n                     )\n \n-            return old_handle_request(self, request, *args, **kwargs)\n+            return old_call_view(registry, request, *args, **kwargs)\n \n-        Router.handle_request = sentry_patched_handle_request\n+        router._call_view = sentry_patched_call_view\n \n         if hasattr(Request, \"invoke_exception_view\"):\n             old_invoke_exception_view = Request.invoke_exception_view\n@@ -101,7 +110,7 @@\n \n             Request.invoke_exception_view = sentry_patched_invoke_exception_view\n \n-        old_wsgi_call = Router.__call__\n+        old_wsgi_call = router.Router.__call__\n \n         def sentry_patched_wsgi_call(self, environ, start_response):\n             # type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse\n@@ -123,7 +132,7 @@\n                 environ, start_response\n             )\n \n-        Router.__call__ = sentry_patched_wsgi_call\n+        router.Router.__call__ = sentry_patched_wsgi_call\n \n \n def _capture_exception(exc_info):\n@@ -196,14 +205,6 @@\n         if request is None:\n             return event\n \n-        try:\n-            if integration.transaction_style == \"route_name\":\n-                event[\"transaction\"] = request.matched_route.name\n-            elif integration.transaction_style == \"route_pattern\":\n-                event[\"transaction\"] = request.matched_route.pattern\n-        except Exception:\n-            pass\n-\n         with capture_internal_exceptions():\n             PyramidRequestExtractor(request).extract_into_event(event)\n", "issue": "Setting transaction name in pyramid\nHi is it possible to set transaction name when using PyramidIntegration?\r\nI tried setting `scope.transaction = \"mycustomname\"` but it seems that integration itself does:\r\n\r\n        try:\r\n            if integration.transaction_style == \"route_name\":\r\n                event[\"transaction\"] = request.matched_route.name\r\n            elif integration.transaction_style == \"route_pattern\":\r\n                event[\"transaction\"] = request.matched_route.pattern\r\n        except Exception:\r\n            pass\r\n\r\nAnd I suspect that overwrites anything I've set up earlier?\n", "before_files": [{"content": "from __future__ import absolute_import\n\nimport os\nimport sys\nimport weakref\n\nfrom pyramid.httpexceptions import HTTPException\nfrom pyramid.request import Request\n\nfrom sentry_sdk.hub import Hub, _should_send_default_pii\nfrom sentry_sdk.utils import capture_internal_exceptions, event_from_exception\nfrom sentry_sdk._compat import reraise, iteritems\n\nfrom sentry_sdk.integrations import Integration\nfrom sentry_sdk.integrations._wsgi_common import RequestExtractor\nfrom sentry_sdk.integrations.wsgi import SentryWsgiMiddleware\n\nfrom sentry_sdk._types import MYPY\n\nif MYPY:\n    from pyramid.response import Response\n    from typing import Any\n    from sentry_sdk.integrations.wsgi import _ScopedResponse\n    from typing import Callable\n    from typing import Dict\n    from typing import Optional\n    from webob.cookies import RequestCookies  # type: ignore\n    from webob.compat import cgi_FieldStorage  # type: ignore\n\n    from sentry_sdk.utils import ExcInfo\n    from sentry_sdk._types import EventProcessor\n\n\nif getattr(Request, \"authenticated_userid\", None):\n\n    def authenticated_userid(request):\n        # type: (Request) -> Optional[Any]\n        return request.authenticated_userid\n\n\nelse:\n    # bw-compat for pyramid < 1.5\n    from pyramid.security import authenticated_userid  # type: ignore\n\n\nTRANSACTION_STYLE_VALUES = (\"route_name\", \"route_pattern\")\n\n\nclass PyramidIntegration(Integration):\n    identifier = \"pyramid\"\n\n    transaction_style = None\n\n    def __init__(self, transaction_style=\"route_name\"):\n        # type: (str) -> None\n        if transaction_style not in TRANSACTION_STYLE_VALUES:\n            raise ValueError(\n                \"Invalid value for transaction_style: %s (must be in %s)\"\n                % (transaction_style, TRANSACTION_STYLE_VALUES)\n            )\n        self.transaction_style = transaction_style\n\n    @staticmethod\n    def setup_once():\n        # type: () -> None\n        from pyramid.router import Router\n        from pyramid.request import Request\n\n        old_handle_request = Router.handle_request\n\n        def sentry_patched_handle_request(self, request, *args, **kwargs):\n            # type: (Any, Request, *Any, **Any) -> Response\n            hub = Hub.current\n            integration = hub.get_integration(PyramidIntegration)\n            if integration is not None:\n                with hub.configure_scope() as scope:\n                    scope.add_event_processor(\n                        _make_event_processor(weakref.ref(request), integration)\n                    )\n\n            return old_handle_request(self, request, *args, **kwargs)\n\n        Router.handle_request = sentry_patched_handle_request\n\n        if hasattr(Request, \"invoke_exception_view\"):\n            old_invoke_exception_view = Request.invoke_exception_view\n\n            def sentry_patched_invoke_exception_view(self, *args, **kwargs):\n                # type: (Request, *Any, **Any) -> Any\n                rv = old_invoke_exception_view(self, *args, **kwargs)\n\n                if (\n                    self.exc_info\n                    and all(self.exc_info)\n                    and rv.status_int == 500\n                    and Hub.current.get_integration(PyramidIntegration) is not None\n                ):\n                    _capture_exception(self.exc_info)\n\n                return rv\n\n            Request.invoke_exception_view = sentry_patched_invoke_exception_view\n\n        old_wsgi_call = Router.__call__\n\n        def sentry_patched_wsgi_call(self, environ, start_response):\n            # type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse\n            hub = Hub.current\n            integration = hub.get_integration(PyramidIntegration)\n            if integration is None:\n                return old_wsgi_call(self, environ, start_response)\n\n            def sentry_patched_inner_wsgi_call(environ, start_response):\n                # type: (Dict[str, Any], Callable[..., Any]) -> Any\n                try:\n                    return old_wsgi_call(self, environ, start_response)\n                except Exception:\n                    einfo = sys.exc_info()\n                    _capture_exception(einfo)\n                    reraise(*einfo)\n\n            return SentryWsgiMiddleware(sentry_patched_inner_wsgi_call)(\n                environ, start_response\n            )\n\n        Router.__call__ = sentry_patched_wsgi_call\n\n\ndef _capture_exception(exc_info):\n    # type: (ExcInfo) -> None\n    if exc_info[0] is None or issubclass(exc_info[0], HTTPException):\n        return\n    hub = Hub.current\n    if hub.get_integration(PyramidIntegration) is None:\n        return\n\n    # If an integration is there, a client has to be there.\n    client = hub.client  # type: Any\n\n    event, hint = event_from_exception(\n        exc_info,\n        client_options=client.options,\n        mechanism={\"type\": \"pyramid\", \"handled\": False},\n    )\n\n    hub.capture_event(event, hint=hint)\n\n\nclass PyramidRequestExtractor(RequestExtractor):\n    def url(self):\n        # type: () -> str\n        return self.request.path_url\n\n    def env(self):\n        # type: () -> Dict[str, str]\n        return self.request.environ\n\n    def cookies(self):\n        # type: () -> RequestCookies\n        return self.request.cookies\n\n    def raw_data(self):\n        # type: () -> str\n        return self.request.text\n\n    def form(self):\n        # type: () -> Dict[str, str]\n        return {\n            key: value\n            for key, value in iteritems(self.request.POST)\n            if not getattr(value, \"filename\", None)\n        }\n\n    def files(self):\n        # type: () -> Dict[str, cgi_FieldStorage]\n        return {\n            key: value\n            for key, value in iteritems(self.request.POST)\n            if getattr(value, \"filename\", None)\n        }\n\n    def size_of_file(self, postdata):\n        # type: (cgi_FieldStorage) -> int\n        file = postdata.file\n        try:\n            return os.fstat(file.fileno()).st_size\n        except Exception:\n            return 0\n\n\ndef _make_event_processor(weak_request, integration):\n    # type: (Callable[[], Request], PyramidIntegration) -> EventProcessor\n    def event_processor(event, hint):\n        # type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any]\n        request = weak_request()\n        if request is None:\n            return event\n\n        try:\n            if integration.transaction_style == \"route_name\":\n                event[\"transaction\"] = request.matched_route.name\n            elif integration.transaction_style == \"route_pattern\":\n                event[\"transaction\"] = request.matched_route.pattern\n        except Exception:\n            pass\n\n        with capture_internal_exceptions():\n            PyramidRequestExtractor(request).extract_into_event(event)\n\n        if _should_send_default_pii():\n            with capture_internal_exceptions():\n                user_info = event.setdefault(\"user\", {})\n                user_info.setdefault(\"id\", authenticated_userid(request))\n\n        return event\n\n    return event_processor\n", "path": "sentry_sdk/integrations/pyramid.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nimport os\nimport sys\nimport weakref\n\nfrom pyramid.httpexceptions import HTTPException\nfrom pyramid.request import Request\n\nfrom sentry_sdk.hub import Hub, _should_send_default_pii\nfrom sentry_sdk.utils import capture_internal_exceptions, event_from_exception\nfrom sentry_sdk._compat import reraise, iteritems\n\nfrom sentry_sdk.integrations import Integration\nfrom sentry_sdk.integrations._wsgi_common import RequestExtractor\nfrom sentry_sdk.integrations.wsgi import SentryWsgiMiddleware\n\nfrom sentry_sdk._types import MYPY\n\nif MYPY:\n    from pyramid.response import Response\n    from typing import Any\n    from sentry_sdk.integrations.wsgi import _ScopedResponse\n    from typing import Callable\n    from typing import Dict\n    from typing import Optional\n    from webob.cookies import RequestCookies  # type: ignore\n    from webob.compat import cgi_FieldStorage  # type: ignore\n\n    from sentry_sdk.utils import ExcInfo\n    from sentry_sdk._types import EventProcessor\n\n\nif getattr(Request, \"authenticated_userid\", None):\n\n    def authenticated_userid(request):\n        # type: (Request) -> Optional[Any]\n        return request.authenticated_userid\n\n\nelse:\n    # bw-compat for pyramid < 1.5\n    from pyramid.security import authenticated_userid  # type: ignore\n\n\nTRANSACTION_STYLE_VALUES = (\"route_name\", \"route_pattern\")\n\n\nclass PyramidIntegration(Integration):\n    identifier = \"pyramid\"\n\n    transaction_style = None\n\n    def __init__(self, transaction_style=\"route_name\"):\n        # type: (str) -> None\n        if transaction_style not in TRANSACTION_STYLE_VALUES:\n            raise ValueError(\n                \"Invalid value for transaction_style: %s (must be in %s)\"\n                % (transaction_style, TRANSACTION_STYLE_VALUES)\n            )\n        self.transaction_style = transaction_style\n\n    @staticmethod\n    def setup_once():\n        # type: () -> None\n        from pyramid import router\n        from pyramid.request import Request\n\n        old_call_view = router._call_view\n\n        def sentry_patched_call_view(registry, request, *args, **kwargs):\n            # type: (Any, Request, *Any, **Any) -> Response\n            hub = Hub.current\n            integration = hub.get_integration(PyramidIntegration)\n\n            if integration is not None:\n                with hub.configure_scope() as scope:\n                    try:\n                        if integration.transaction_style == \"route_name\":\n                            scope.transaction = request.matched_route.name\n                        elif integration.transaction_style == \"route_pattern\":\n                            scope.transaction = request.matched_route.pattern\n                    except Exception:\n                        raise\n\n                    scope.add_event_processor(\n                        _make_event_processor(weakref.ref(request), integration)\n                    )\n\n            return old_call_view(registry, request, *args, **kwargs)\n\n        router._call_view = sentry_patched_call_view\n\n        if hasattr(Request, \"invoke_exception_view\"):\n            old_invoke_exception_view = Request.invoke_exception_view\n\n            def sentry_patched_invoke_exception_view(self, *args, **kwargs):\n                # type: (Request, *Any, **Any) -> Any\n                rv = old_invoke_exception_view(self, *args, **kwargs)\n\n                if (\n                    self.exc_info\n                    and all(self.exc_info)\n                    and rv.status_int == 500\n                    and Hub.current.get_integration(PyramidIntegration) is not None\n                ):\n                    _capture_exception(self.exc_info)\n\n                return rv\n\n            Request.invoke_exception_view = sentry_patched_invoke_exception_view\n\n        old_wsgi_call = router.Router.__call__\n\n        def sentry_patched_wsgi_call(self, environ, start_response):\n            # type: (Any, Dict[str, str], Callable[..., Any]) -> _ScopedResponse\n            hub = Hub.current\n            integration = hub.get_integration(PyramidIntegration)\n            if integration is None:\n                return old_wsgi_call(self, environ, start_response)\n\n            def sentry_patched_inner_wsgi_call(environ, start_response):\n                # type: (Dict[str, Any], Callable[..., Any]) -> Any\n                try:\n                    return old_wsgi_call(self, environ, start_response)\n                except Exception:\n                    einfo = sys.exc_info()\n                    _capture_exception(einfo)\n                    reraise(*einfo)\n\n            return SentryWsgiMiddleware(sentry_patched_inner_wsgi_call)(\n                environ, start_response\n            )\n\n        router.Router.__call__ = sentry_patched_wsgi_call\n\n\ndef _capture_exception(exc_info):\n    # type: (ExcInfo) -> None\n    if exc_info[0] is None or issubclass(exc_info[0], HTTPException):\n        return\n    hub = Hub.current\n    if hub.get_integration(PyramidIntegration) is None:\n        return\n\n    # If an integration is there, a client has to be there.\n    client = hub.client  # type: Any\n\n    event, hint = event_from_exception(\n        exc_info,\n        client_options=client.options,\n        mechanism={\"type\": \"pyramid\", \"handled\": False},\n    )\n\n    hub.capture_event(event, hint=hint)\n\n\nclass PyramidRequestExtractor(RequestExtractor):\n    def url(self):\n        # type: () -> str\n        return self.request.path_url\n\n    def env(self):\n        # type: () -> Dict[str, str]\n        return self.request.environ\n\n    def cookies(self):\n        # type: () -> RequestCookies\n        return self.request.cookies\n\n    def raw_data(self):\n        # type: () -> str\n        return self.request.text\n\n    def form(self):\n        # type: () -> Dict[str, str]\n        return {\n            key: value\n            for key, value in iteritems(self.request.POST)\n            if not getattr(value, \"filename\", None)\n        }\n\n    def files(self):\n        # type: () -> Dict[str, cgi_FieldStorage]\n        return {\n            key: value\n            for key, value in iteritems(self.request.POST)\n            if getattr(value, \"filename\", None)\n        }\n\n    def size_of_file(self, postdata):\n        # type: (cgi_FieldStorage) -> int\n        file = postdata.file\n        try:\n            return os.fstat(file.fileno()).st_size\n        except Exception:\n            return 0\n\n\ndef _make_event_processor(weak_request, integration):\n    # type: (Callable[[], Request], PyramidIntegration) -> EventProcessor\n    def event_processor(event, hint):\n        # type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any]\n        request = weak_request()\n        if request is None:\n            return event\n\n        with capture_internal_exceptions():\n            PyramidRequestExtractor(request).extract_into_event(event)\n\n        if _should_send_default_pii():\n            with capture_internal_exceptions():\n                user_info = event.setdefault(\"user\", {})\n                user_info.setdefault(\"id\", authenticated_userid(request))\n\n        return event\n\n    return event_processor\n", "path": "sentry_sdk/integrations/pyramid.py"}]}