Skip to content

Commit edbabcf

Browse files
authored
ref: Drop Falcon < 3.0 (#7004)
1 parent 6b1e8a1 commit edbabcf

6 files changed

Lines changed: 1177 additions & 52 deletions

File tree

MIGRATION_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
3030
- Dropped support for Django versions below 2.0.
3131
- Dropped support for gevent versions below 20.9.
3232
- Dropped support for greenlet versions below 0.4.17.
33+
- Dropped support for Falcon versions below 3.0.
3334
- Dropped support for Flask below 2.0.
3435
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.
3536
- The deprecated `push_scope` and `configure_scope` APIs have been removed. Use `with new_scope():` to push a new scope and `scope = get_current_scope()` to retrieve the current scope instead.

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 315 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/populate_tox/releases.jsonl

Lines changed: 845 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sentry_sdk/integrations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def iter_default_integrations(
137137
"cohere": (5, 4, 0),
138138
"django": (2, 0),
139139
"dramatiq": (1, 9),
140-
"falcon": (1, 4),
140+
"falcon": (3, 0),
141141
"fastapi": (0, 79, 0),
142142
"flask": (2, 0, 0),
143143
"gql": (3, 4, 1),

sentry_sdk/integrations/falcon.py

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,12 @@
2323

2424
try:
2525
import falcon # type: ignore
26+
from falcon import App, app_helpers
2627
from falcon import __version__ as FALCON_VERSION
28+
from falcon.request import _UNSET as _FALCON_UNSET # type: ignore
2729
except ImportError:
2830
raise DidNotEnable("Falcon not installed")
2931

30-
try:
31-
import falcon.app_helpers # type: ignore
32-
33-
falcon_helpers = falcon.app_helpers
34-
falcon_app_class = falcon.App
35-
FALCON3 = True
36-
except ImportError:
37-
import falcon.api_helpers # type: ignore
38-
39-
falcon_helpers = falcon.api_helpers
40-
falcon_app_class = falcon.API
41-
FALCON3 = False
42-
43-
44-
_FALCON_UNSET: "Optional[object]" = None
45-
if FALCON3: # falcon.request._UNSET is only available in Falcon 3.0+
46-
with capture_internal_exceptions():
47-
from falcon.request import ( # type: ignore[import-not-found, no-redef]
48-
_UNSET as _FALCON_UNSET,
49-
)
50-
5132

5233
class FalconRequestExtractor(RequestExtractor):
5334
def env(self) -> "Dict[str, Any]":
@@ -137,23 +118,22 @@ class FalconIntegration(Integration):
137118
def __init__(self, transaction_style: str = "uri_template") -> None:
138119
if transaction_style not in TRANSACTION_STYLE_VALUES:
139120
raise ValueError(
140-
"Invalid value for transaction_style: %s (must be in %s)"
141-
% (transaction_style, TRANSACTION_STYLE_VALUES)
121+
f"Invalid value for transaction_style: {transaction_style} "
122+
f"(must be in {TRANSACTION_STYLE_VALUES})"
142123
)
143124
self.transaction_style = transaction_style
144125

145126
@staticmethod
146127
def setup_once() -> None:
147-
version = parse_version(FALCON_VERSION)
148-
_check_minimum_version(FalconIntegration, version)
128+
_check_minimum_version(FalconIntegration, parse_version(FALCON_VERSION))
149129

150130
_patch_wsgi_app()
151131
_patch_handle_exception()
152132
_patch_prepare_middleware()
153133

154134

155135
def _patch_wsgi_app() -> None:
156-
original_wsgi_app = falcon_app_class.__call__
136+
original_wsgi_app = App.__call__
157137

158138
def sentry_patched_wsgi_app(
159139
self: "falcon.API", env: "Any", start_response: "Any"
@@ -169,11 +149,11 @@ def sentry_patched_wsgi_app(
169149

170150
return sentry_wrapped(env, start_response)
171151

172-
falcon_app_class.__call__ = sentry_patched_wsgi_app
152+
App.__call__ = sentry_patched_wsgi_app
173153

174154

175155
def _patch_handle_exception() -> None:
176-
original_handle_exception = falcon_app_class._handle_exception
156+
original_handle_exception = App._handle_exception
177157

178158
@ensure_integration_enabled(FalconIntegration, original_handle_exception)
179159
def sentry_patched_handle_exception(self: "falcon.API", *args: "Any") -> "Any":
@@ -205,11 +185,11 @@ def sentry_patched_handle_exception(self: "falcon.API", *args: "Any") -> "Any":
205185

206186
return was_handled
207187

208-
falcon_app_class._handle_exception = sentry_patched_handle_exception
188+
App._handle_exception = sentry_patched_handle_exception
209189

210190

211191
def _patch_prepare_middleware() -> None:
212-
original_prepare_middleware = falcon_helpers.prepare_middleware
192+
original_prepare_middleware = app_helpers.prepare_middleware
213193

214194
def sentry_patched_prepare_middleware(
215195
middleware: "Any" = None,
@@ -224,11 +204,9 @@ def sentry_patched_prepare_middleware(
224204
if integration is not None:
225205
middleware = [SentryFalconMiddleware()] + (middleware or [])
226206

227-
# We intentionally omit the asgi argument here, since the default is False anyways,
228-
# and this way, we remain backwards-compatible with pre-3.0.0 Falcon versions.
229-
return original_prepare_middleware(middleware, independent_middleware)
207+
return original_prepare_middleware(middleware, independent_middleware, asgi)
230208

231-
falcon_helpers.prepare_middleware = sentry_patched_prepare_middleware
209+
app_helpers.prepare_middleware = sentry_patched_prepare_middleware
232210

233211

234212
def _exception_leads_to_http_5xx(ex: Exception, response: "falcon.Response") -> bool:
@@ -239,14 +217,7 @@ def _exception_leads_to_http_5xx(ex: Exception, response: "falcon.Response") ->
239217
ex, (falcon.HTTPError, falcon.http_status.HTTPStatus)
240218
)
241219

242-
# We only check the HTTP status on Falcon 3 because in Falcon 2, the status on the response
243-
# at the stage where we capture it is listed as 200, even though we would expect to see a 500
244-
# status. Since at the time of this change, Falcon 2 is ca. 4 years old, we have decided to
245-
# only perform this check on Falcon 3+, despite the risk that some handled errors might be
246-
# reported to Sentry as unhandled on Falcon 2.
247-
return (is_server_error or is_unhandled_error) and (
248-
not FALCON3 or _has_http_5xx_status(response)
249-
)
220+
return (is_server_error or is_unhandled_error) and _has_http_5xx_status(response)
250221

251222

252223
def _has_http_5xx_status(response: "falcon.Response") -> bool:

tox.ini

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)