|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
3 |
| -import inspect |
4 |
| -import threading |
5 |
| - |
6 | 3 | from sentry_sdk.hub import _should_send_default_pii, Hub
|
7 | 4 | from sentry_sdk.integrations import DidNotEnable, Integration
|
8 | 5 | from sentry_sdk.integrations._wsgi_common import _filter_headers
|
|
14 | 11 | event_from_exception,
|
15 | 12 | )
|
16 | 13 |
|
17 |
| -from sentry_sdk._functools import wraps |
18 | 14 | from sentry_sdk._types import MYPY
|
19 | 15 |
|
20 | 16 | if MYPY:
|
|
38 | 34 | request,
|
39 | 35 | websocket,
|
40 | 36 | )
|
41 |
| - from quart.scaffold import Scaffold # type: ignore |
42 | 37 | from quart.signals import ( # type: ignore
|
43 | 38 | got_background_exception,
|
44 | 39 | got_request_exception,
|
45 | 40 | got_websocket_exception,
|
46 | 41 | request_started,
|
47 | 42 | websocket_started,
|
48 | 43 | )
|
49 |
| - from quart.utils import is_coroutine_function # type: ignore |
50 | 44 | except ImportError:
|
51 | 45 | raise DidNotEnable("Quart is not installed")
|
52 | 46 |
|
@@ -77,62 +71,18 @@ def setup_once():
|
77 | 71 | got_request_exception.connect(_capture_exception)
|
78 | 72 | got_websocket_exception.connect(_capture_exception)
|
79 | 73 |
|
80 |
| - patch_asgi_app() |
81 |
| - patch_scaffold_route() |
82 |
| - |
83 |
| - |
84 |
| -def patch_asgi_app(): |
85 |
| - # type: () -> None |
86 |
| - old_app = Quart.__call__ |
87 |
| - |
88 |
| - async def sentry_patched_asgi_app(self, scope, receive, send): |
89 |
| - # type: (Any, Any, Any, Any) -> Any |
90 |
| - if Hub.current.get_integration(QuartIntegration) is None: |
91 |
| - return await old_app(self, scope, receive, send) |
92 |
| - |
93 |
| - middleware = SentryAsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw)) |
94 |
| - middleware.__call__ = middleware._run_asgi3 |
95 |
| - return await middleware(scope, receive, send) |
96 |
| - |
97 |
| - Quart.__call__ = sentry_patched_asgi_app |
98 |
| - |
99 |
| - |
100 |
| -def patch_scaffold_route(): |
101 |
| - # type: () -> None |
102 |
| - old_route = Scaffold.route |
103 |
| - |
104 |
| - def _sentry_route(*args, **kwargs): |
105 |
| - # type: (*Any, **Any) -> Any |
106 |
| - old_decorator = old_route(*args, **kwargs) |
107 |
| - |
108 |
| - def decorator(old_func): |
109 |
| - # type: (Any) -> Any |
110 |
| - |
111 |
| - if inspect.isfunction(old_func) and not is_coroutine_function(old_func): |
112 |
| - |
113 |
| - @wraps(old_func) |
114 |
| - def _sentry_func(*args, **kwargs): |
115 |
| - # type: (*Any, **Any) -> Any |
116 |
| - hub = Hub.current |
117 |
| - integration = hub.get_integration(QuartIntegration) |
118 |
| - if integration is None: |
119 |
| - return old_func(*args, **kwargs) |
120 |
| - |
121 |
| - with hub.configure_scope() as sentry_scope: |
122 |
| - if sentry_scope.profile is not None: |
123 |
| - sentry_scope.profile.active_thread_id = ( |
124 |
| - threading.current_thread().ident |
125 |
| - ) |
126 |
| - |
127 |
| - return old_func(*args, **kwargs) |
128 |
| - |
129 |
| - return old_decorator(_sentry_func) |
| 74 | + old_app = Quart.__call__ |
130 | 75 |
|
131 |
| - return old_decorator(old_func) |
| 76 | + async def sentry_patched_asgi_app(self, scope, receive, send): |
| 77 | + # type: (Any, Any, Any, Any) -> Any |
| 78 | + if Hub.current.get_integration(QuartIntegration) is None: |
| 79 | + return await old_app(self, scope, receive, send) |
132 | 80 |
|
133 |
| - return decorator |
| 81 | + middleware = SentryAsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw)) |
| 82 | + middleware.__call__ = middleware._run_asgi3 |
| 83 | + return await middleware(scope, receive, send) |
134 | 84 |
|
135 |
| - Scaffold.route = _sentry_route |
| 85 | + Quart.__call__ = sentry_patched_asgi_app |
136 | 86 |
|
137 | 87 |
|
138 | 88 | def _set_transaction_name_and_source(scope, transaction_style, request):
|
|
0 commit comments