Skip to content

Commit 47b88db

Browse files
committed
Update litestar integration
1 parent 1fd2b86 commit 47b88db

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

sentry_sdk/integrations/litestar.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from collections.abc import Set
12
import sentry_sdk
23
from sentry_sdk.consts import OP
3-
from sentry_sdk.integrations import DidNotEnable, Integration
4+
from sentry_sdk.integrations import _DEFAULT_FAILED_REQUEST_STATUS_CODES, DidNotEnable, Integration
45
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
56
from sentry_sdk.integrations.logging import ignore_logger
67
from sentry_sdk.scope import should_send_default_pii
@@ -17,6 +18,7 @@
1718
from litestar.middleware import DefineMiddleware # type: ignore
1819
from litestar.routes.http import HTTPRoute # type: ignore
1920
from litestar.data_extractors import ConnectionDataExtractor # type: ignore
21+
from litestar.exceptions import HTTPException # type: ignore
2022
except ImportError:
2123
raise DidNotEnable("Litestar is not installed")
2224

@@ -45,6 +47,11 @@ class LitestarIntegration(Integration):
4547
identifier = "litestar"
4648
origin = f"auto.http.{identifier}"
4749

50+
def __init__(self,
51+
failed_request_status_codes=_DEFAULT_FAILED_REQUEST_STATUS_CODES, # type: Set[int]
52+
) -> None:
53+
self.failed_request_status_codes = failed_request_status_codes
54+
4855
@staticmethod
4956
def setup_once():
5057
# type: () -> None
@@ -277,6 +284,13 @@ def exception_handler(exc, scope):
277284
sentry_scope = sentry_sdk.get_isolation_scope()
278285
sentry_scope.set_user(user_info)
279286

287+
if isinstance(exc, HTTPException):
288+
integration = sentry_sdk.get_client().get_integration(
289+
LitestarIntegration
290+
)
291+
if integration is not None and exc.status_code not in integration.failed_request_status_codes:
292+
return
293+
280294
event, hint = event_from_exception(
281295
exc,
282296
client_options=sentry_sdk.get_client().options,

0 commit comments

Comments
 (0)