Skip to content

Commit b0f2f41

Browse files
Gleekzonesentry-bot
and
sentry-bot
authored
fix(chalice): Enable support for Chalice 1.20 (getsentry#832)
Co-authored-by: sentry-bot <markus+ghbot@sentry.io>
1 parent 34f1cbd commit b0f2f41

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

sentry_sdk/integrations/chalice.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from sentry_sdk._compat import reraise
44
from sentry_sdk.hub import Hub
5-
from sentry_sdk.integrations import Integration
5+
from sentry_sdk.integrations import Integration, DidNotEnable
66
from sentry_sdk.integrations.aws_lambda import _make_request_event_processor
77
from sentry_sdk.utils import (
88
capture_internal_exceptions,
@@ -22,6 +22,11 @@
2222

2323
F = TypeVar("F", bound=Callable[..., Any])
2424

25+
try:
26+
from chalice import __version__ as CHALICE_VERSION
27+
except ImportError:
28+
raise DidNotEnable("Chalice is not installed")
29+
2530

2631
class EventSourceHandler(ChaliceEventSourceHandler): # type: ignore
2732
def __call__(self, event, context):
@@ -36,8 +41,7 @@ def __call__(self, event, context):
3641
_make_request_event_processor(event, context, configured_time)
3742
)
3843
try:
39-
event_obj = self.event_class(event, context)
40-
return self.func(event_obj)
44+
return ChaliceEventSourceHandler.__call__(self, event, context)
4145
except Exception:
4246
exc_info = sys.exc_info()
4347
event, hint = event_from_exception(
@@ -92,7 +96,18 @@ class ChaliceIntegration(Integration):
9296
@staticmethod
9397
def setup_once():
9498
# 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+
)
96111

97112
def sentry_event_response(app, view_function, function_args):
98113
# type: (Any, F, **Any) -> Any
@@ -104,6 +119,9 @@ def sentry_event_response(app, view_function, function_args):
104119
app, wrapped_view_function, function_args
105120
)
106121

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
108126
# for everything else (like events)
109127
chalice.app.EventSourceHandler = EventSourceHandler

tox.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ envlist =
7777

7878
{py3.5,py3.6,py3.7,py3.8,py3.9}-pure_eval
7979

80-
{py3.6,py3.7,py3.8}-chalice-{1.16,1.17,1.18,1.19}
80+
{py3.6,py3.7,py3.8}-chalice-{1.16,1.17,1.18,1.19,1.20}
8181

8282
[testenv]
8383
deps =
@@ -204,6 +204,7 @@ deps =
204204
chalice-1.17: chalice>=1.17.0,<1.18.0
205205
chalice-1.18: chalice>=1.18.0,<1.19.0
206206
chalice-1.19: chalice>=1.19.0,<1.20.0
207+
chalice-1.20: chalice>=1.20.0,<1.21.0
207208
chalice: pytest-chalice==0.0.5
208209

209210
setenv =

0 commit comments

Comments
 (0)