We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Integration with Pyramid tweens
The common case in Pyramid is to handle exception with [tweens](https://docs.pylonsproject.org/projects/pyramid/en/latest/glossary.html#term-tween) that seat atop of main Pyramid handling function. With a current integration [approach](https://docs.sentry.io/platforms/python/pyramid/) each exception occurring in main function goes to sentry. Is there a way to track just those errors that were not handled in tweens?

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

{"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@@ -59,6 +59,7 @@\n     def setup_once():\n         # type: () -> None\n         from pyramid.router import Router  # type: ignore\n+        from pyramid.request import Request  # type: ignore\n \n         old_handle_request = Router.handle_request\n \n@@ -66,23 +67,34 @@\n             # type: (Any, Request, *Any, **Any) -> Response\n             hub = Hub.current\n             integration = hub.get_integration(PyramidIntegration)\n-            if integration is None:\n-                return old_handle_request(self, request, *args, **kwargs)\n-\n-            with hub.configure_scope() as scope:\n-                scope.add_event_processor(\n-                    _make_event_processor(weakref.ref(request), integration)\n-                )\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-            try:\n-                return old_handle_request(self, request, *args, **kwargs)\n-            except Exception:\n-                exc_info = sys.exc_info()\n-                _capture_exception(exc_info)\n-                reraise(*exc_info)\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+                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@@ -92,15 +104,23 @@\n             if integration is None:\n                 return old_wsgi_call(self, environ, start_response)\n \n-            return SentryWsgiMiddleware(lambda *a, **kw: old_wsgi_call(self, *a, **kw))(\n+            def sentry_patched_inner_wsgi_call(environ, start_response):\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 \n-def _capture_exception(exc_info, **kwargs):\n-    # type: (ExcInfo, **Any) -> None\n+def _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", "issue": "Integration with Pyramid tweens\nThe common case in Pyramid is to handle exception with [tweens](https://docs.pylonsproject.org/projects/pyramid/en/latest/glossary.html#term-tween) that seat atop of main Pyramid handling function. With a current integration [approach](https://docs.sentry.io/platforms/python/pyramid/) each exception occurring in main function goes to sentry. Is there a way to track just those errors that were not handled in tweens?\n", "before_files": [{"content": "from __future__ import absolute_import\n\nimport os\nimport sys\nimport weakref\n\nfrom pyramid.httpexceptions import HTTPException  # type: ignore\nfrom pyramid.request import Request  # type: ignore\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\nif False:\n    from pyramid.response import Response  # type: ignore\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\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\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        TRANSACTION_STYLE_VALUES = (\"route_name\", \"route_pattern\")\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  # type: ignore\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 None:\n                return old_handle_request(self, request, *args, **kwargs)\n\n            with hub.configure_scope() as scope:\n                scope.add_event_processor(\n                    _make_event_processor(weakref.ref(request), integration)\n                )\n\n            try:\n                return old_handle_request(self, request, *args, **kwargs)\n            except Exception:\n                exc_info = sys.exc_info()\n                _capture_exception(exc_info)\n                reraise(*exc_info)\n\n        Router.handle_request = sentry_patched_handle_request\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) -> _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            return SentryWsgiMiddleware(lambda *a, **kw: old_wsgi_call(self, *a, **kw))(\n                environ, start_response\n            )\n\n        Router.__call__ = sentry_patched_wsgi_call\n\n\ndef _capture_exception(exc_info, **kwargs):\n    # type: (ExcInfo, **Any) -> 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    event, hint = event_from_exception(\n        exc_info,\n        client_options=hub.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        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) -> Callable\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[\"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  # type: ignore\nfrom pyramid.request import Request  # type: ignore\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\nif False:\n    from pyramid.response import Response  # type: ignore\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\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\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        TRANSACTION_STYLE_VALUES = (\"route_name\", \"route_pattern\")\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  # type: ignore\n        from pyramid.request import Request  # type: ignore\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                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) -> _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                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    event, hint = event_from_exception(\n        exc_info,\n        client_options=hub.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        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) -> Callable\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[\"id\"] = authenticated_userid(request)\n\n        return event\n\n    return event_processor\n", "path": "sentry_sdk/integrations/pyramid.py"}]}