@@ -95,7 +95,6 @@ class SentryAsgiMiddleware:
9595 "mechanism_type" ,
9696 "span_origin" ,
9797 "http_methods_to_capture" ,
98- "suppress_chained_exceptions" ,
9998 )
10099
101100 def __init__ (
@@ -107,7 +106,6 @@ def __init__(
107106 span_origin : str = "manual" ,
108107 http_methods_to_capture : "Tuple[str, ...]" = DEFAULT_HTTP_METHODS_TO_CAPTURE ,
109108 asgi_version : "Optional[int]" = None ,
110- suppress_chained_exceptions : "bool" = True ,
111109 ) -> None :
112110 """
113111 Instrument an ASGI application with Sentry. Provides HTTP/websocket
@@ -144,7 +142,6 @@ def __init__(
144142 self .span_origin = span_origin
145143 self .app = app
146144 self .http_methods_to_capture = http_methods_to_capture
147- self .suppress_chained_exceptions = suppress_chained_exceptions
148145
149146 if asgi_version is None :
150147 if _looks_like_asgi3 (app ):
@@ -193,13 +190,18 @@ async def _run_app(
193190 return await self .app (scope , receive , send )
194191
195192 except Exception as exc :
196- if self .suppress_chained_exceptions :
193+ suppress_chained_exceptions = (
194+ sentry_sdk .get_client ()
195+ .options .get ("_experiments" , {})
196+ .get ("suppress_asgi_chained_exceptions" , False )
197+ )
198+ if suppress_chained_exceptions :
197199 self ._capture_lifespan_exception (exc )
198200 raise exc from None
199201
200202 exc_info = sys .exc_info ()
201203 with capture_internal_exceptions ():
202- self ._capture_request_exception (exc )
204+ self ._capture_lifespan_exception (exc )
203205 reraise (* exc_info )
204206
205207 client = sentry_sdk .get_client ()
@@ -335,7 +337,12 @@ async def _sentry_wrapped_send(
335337 scope , receive , _sentry_wrapped_send
336338 )
337339 except Exception as exc :
338- if self .suppress_chained_exceptions :
340+ suppress_chained_exceptions = (
341+ sentry_sdk .get_client ()
342+ .options .get ("_experiments" , {})
343+ .get ("suppress_asgi_chained_exceptions" , False )
344+ )
345+ if suppress_chained_exceptions :
339346 self ._capture_request_exception (exc )
340347 raise exc from None
341348
0 commit comments