File tree Expand file tree Collapse file tree 3 files changed +13
-12
lines changed
Expand file tree Collapse file tree 3 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -42,17 +42,11 @@ def main():
4242 for module_path in walk_package_modules ():
4343 scan_file (module_path )
4444
45- # TODO: Investigate why we suppress exception chains here.
46- ignored_raises = {
47- pathlib .Path ("sentry_sdk/integrations/asgi.py" ): 2 ,
48- pathlib .Path ("sentry_sdk/integrations/asyncio.py" ): 1 ,
49- }
50-
5145 raise_from_none_count = {
5246 file : len (occurences )
5347 for file , occurences in RaiseFromNoneVisitor .line_numbers .items ()
5448 }
55- if raise_from_none_count != ignored_raises :
49+ if raise_from_none_count :
5650 exc = Exception ("Detected unexpected raise ... from None." )
5751 exc .add_note (
5852 "Raise ... from None suppresses chained exceptions, removing valuable context."
Original file line number Diff line number Diff line change 44Based on Tom Christie's `sentry-asgi <https://github.com/encode/sentry-asgi>`.
55"""
66
7+ import sys
78import asyncio
89import inspect
910from copy import deepcopy
3738 logger ,
3839 transaction_from_function ,
3940 _get_installed_modules ,
41+ capture_internal_exceptions ,
42+ reraise ,
4043)
4144
4245from typing import TYPE_CHECKING
@@ -187,8 +190,10 @@ async def _run_app(
187190 return await self .app (scope , receive , send )
188191
189192 except Exception as exc :
190- self ._capture_lifespan_exception (exc )
191- raise exc from None
193+ exc_info = sys .exc_info ()
194+ with capture_internal_exceptions ():
195+ self ._capture_lifespan_exception (exc )
196+ reraise (* exc_info )
192197
193198 client = sentry_sdk .get_client ()
194199 span_streaming = has_span_streaming_enabled (client .options )
@@ -323,8 +328,10 @@ async def _sentry_wrapped_send(
323328 scope , receive , _sentry_wrapped_send
324329 )
325330 except Exception as exc :
326- self ._capture_request_exception (exc )
327- raise exc from None
331+ exc_info = sys .exc_info ()
332+ with capture_internal_exceptions ():
333+ self ._capture_request_exception (exc )
334+ reraise (* exc_info )
328335 finally :
329336 _asgi_middleware_applied .set (False )
330337
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ async def _task_with_sentry_span_creation() -> "Any":
7979 try :
8080 result = await coro
8181 except StopAsyncIteration as e :
82- raise e from None
82+ raise
8383 except Exception :
8484 reraise (* _capture_exception ())
8585
You can’t perform that action at this time.
0 commit comments