2
2
3
3
from sentry_sdk ._compat import reraise
4
4
from sentry_sdk .hub import Hub
5
- from sentry_sdk .integrations import Integration
5
+ from sentry_sdk .integrations import Integration , DidNotEnable
6
6
from sentry_sdk .integrations .aws_lambda import _make_request_event_processor
7
7
from sentry_sdk .utils import (
8
8
capture_internal_exceptions ,
22
22
23
23
F = TypeVar ("F" , bound = Callable [..., Any ])
24
24
25
+ try :
26
+ from chalice import __version__ as CHALICE_VERSION
27
+ except ImportError :
28
+ raise DidNotEnable ("Chalice is not installed" )
29
+
25
30
26
31
class EventSourceHandler (ChaliceEventSourceHandler ): # type: ignore
27
32
def __call__ (self , event , context ):
@@ -36,8 +41,7 @@ def __call__(self, event, context):
36
41
_make_request_event_processor (event , context , configured_time )
37
42
)
38
43
try :
39
- event_obj = self .event_class (event , context )
40
- return self .func (event_obj )
44
+ return ChaliceEventSourceHandler .__call__ (self , event , context )
41
45
except Exception :
42
46
exc_info = sys .exc_info ()
43
47
event , hint = event_from_exception (
@@ -92,7 +96,18 @@ class ChaliceIntegration(Integration):
92
96
@staticmethod
93
97
def setup_once ():
94
98
# type: () -> None
95
- old_get_view_function_response = Chalice ._get_view_function_response
99
+ try :
100
+ version = tuple (map (int , CHALICE_VERSION .split ("." )[:3 ]))
101
+ except (ValueError , TypeError ):
102
+ raise DidNotEnable ("Unparsable Chalice version: {}" .format (CHALICE_VERSION ))
103
+ if version < (1 , 20 ):
104
+ old_get_view_function_response = Chalice ._get_view_function_response
105
+ else :
106
+ from chalice .app import RestAPIEventHandler
107
+
108
+ old_get_view_function_response = (
109
+ RestAPIEventHandler ._get_view_function_response
110
+ )
96
111
97
112
def sentry_event_response (app , view_function , function_args ):
98
113
# type: (Any, F, **Any) -> Any
@@ -104,6 +119,9 @@ def sentry_event_response(app, view_function, function_args):
104
119
app , wrapped_view_function , function_args
105
120
)
106
121
107
- Chalice ._get_view_function_response = sentry_event_response
122
+ if version < (1 , 20 ):
123
+ Chalice ._get_view_function_response = sentry_event_response
124
+ else :
125
+ RestAPIEventHandler ._get_view_function_response = sentry_event_response
108
126
# for everything else (like events)
109
127
chalice .app .EventSourceHandler = EventSourceHandler
0 commit comments