Title: Sentry removes chained exceptions during ASGI application crash · Issue #5624 · getsentry/sentry-python · GitHub
Open Graph Title: Sentry removes chained exceptions during ASGI application crash · Issue #5624 · getsentry/sentry-python
X Title: Sentry removes chained exceptions during ASGI application crash · Issue #5624 · getsentry/sentry-python
Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.35.0 Steps to Reproduce We have an ASGI application; we use Sentry in it, by way of calling sentry_sdk.init. We recently had a incident; during that incident, the ASGI application ...
Open Graph Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.35.0 Steps to Reproduce We have an ASGI application; we use Sentry in it, by way of calling sentry_sdk.init. We recently had a incident; dur...
X Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.35.0 Steps to Reproduce We have an ASGI application; we use Sentry in it, by way of calling sentry_sdk.init. We recently had a incident; dur...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/5624
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sentry removes chained exceptions during ASGI application crash","articleBody":"### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Version\n\n2.35.0\n\n### Steps to Reproduce\n\nWe have an ASGI application; we use Sentry in it, by way of calling `sentry_sdk.init`.\n\nWe recently had a incident; during that incident, the ASGI application was crashing. Our logs contained:\n```\n2026-03-03 16:59:59,994 - uvicorn.error - ERROR - Exception in ASGI application\nTraceback (most recent call last):\n File \"/…/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py\", line 366, in run_asgi\n result = await app(self.scope, self.receive, self.send)\n[snipped]\n File \"/…/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py\", line 408, in _sentry_patched_asgi_app\n return await middleware(scope, receive, send)\n File \"/…/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py\", line 179, in _run_asgi3\n return await self._run_app(scope, receive, send, asgi_version=3)\n File \"/…/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py\", line 268, in _run_app\n raise exc from None\n File \"/…/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py\", line 263, in _run_app\n return await self.app(\n File \"/…/.venv/lib/python3.10/site-packages/starlette/applications.py\", line 113, in __call__\n await self.middleware_stack(scope, receive, send)\n File \"/…/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py\", line 150, in _create_span_call\n return await old_call(app, scope, receive, send, **kwargs)\n[snip more frames]\n File \"/…/app/middleware/authorization_middleware.py\", line 79, in __call__\n verifier.verify(token, request)\n File \"/…/app/token_verifier.py\", line 72, in verify\n raise HTTPException(\nstarlette.exceptions.HTTPException: 401: Failed to Authorize\"\n```\n\nNow, that exception is a bug; I think we're supposed to return a 401 _response_, not raise.\n\nBut what hampered us during this incident is that line 72 there is:\n```\n except Exception as e:\n raise HTTPException(\n status_code=status.HTTP_401_UNAUTHORIZED,\n detail=\"Failed to Authorize\",\n headers={\"WWW-Authenticate\": \"Bearer\"},\n ) from e\n```\n\n(Note that this is still our code.) Note the `from e`: there should be an additional exception's worth of stack frames, but the stack trace above terminated there. That is, `from e` should normally look something like this:\n\n```\nTraceback (most recent call last):\n[snip]\nRuntimeError: I couldn't do it.\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n[snip]\n raise RuntimeError(\"ouch\") from e\nRuntimeError: ouch\n```\n\nHaving the first bit (this exception led to the second exception) _would have really helped us in the incident._\n\nBy default, FastAPI / Uvicorn will emit that \"The above exception was …\" bit automatically. In fact, I copy/pasted that snippet from a test FastAPI app. So, in a small test, it works; in our production code, not so much.\n\nThis frame in Sentry's code, I think, is why we do _not_, in prod, get chained exceptions in the backtrace:\n```\n File \"/…/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py\", line 268, in _run_app\n raise exc from None\n```\n\nThat code is [here](https://github.com/getsentry/sentry-python/blob/2.35.0/sentry_sdk/integrations/asgi.py#L268).\n\nThat `from None` removes the context/exception cause from the exception. There does not seem to be a reason for that in the linked code; this means we lose the context from the exception in our logs.\n\nThere is also [this line](https://github.com/getsentry/sentry-python/blob/2.35.0/sentry_sdk/integrations/asgi.py#L194), and I think both `from None`s are incorrect.\n\n**Sentry should re-propagate the current exception with whatever `__context__`/`__cause__` is has.** A simple `raise` (without \"`exc`\") is sufficient.\n\nSee [Exception Chaining](https://docs.python.org/3/tutorial/errors.html#exception-chaining) in the Python docs for more information.\n\n### Expected Result\n\nSentry does not de-chain exceptions during an ASGI crash\n\n### Actual Result\n\nSentry de-chains the exception, resulting in our logging library not logging a full stack trace.","author":{"url":"https://github.com/roy-work","@type":"Person","name":"roy-work"},"datePublished":"2026-03-10T01:24:26Z","url":"https://github.com/getsentry/sentry-python/issues/5624"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2ff0e7e8-5fb9-18f9-a20e-a289e70af575 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCAC:842EC:7E7B24:AAB1B7:6B00E06A |
| html-safe-nonce | 0bc32717c22bd42c7ba20bf7a9bdfbb546cb5a11de886154020eebc1fb88722f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0FDOjg0MkVDOjdFN0IyNDpBQUIxQjc6NkIwMEUwNkEiLCJ2aXNpdG9yX2lkIjoiNjc0MzAxMTE5MzgwMTIwMzgxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3b332b46201764166d965773db3154ff1a910c5fbfc2935b7a80d8a871217cb4 |
| hovercard-subject-tag | issue:4048796195 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/5624/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a1cf8ea0341d8a13293ecd9990047796316ec0ca12e33e1723161b3e67d95510/getsentry/sentry-python/issues/5624 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a1cf8ea0341d8a13293ecd9990047796316ec0ca12e33e1723161b3e67d95510/getsentry/sentry-python/issues/5624 |
| og:image:alt | How do you use Sentry? Sentry Saas (sentry.io) Version 2.35.0 Steps to Reproduce We have an ASGI application; we use Sentry in it, by way of calling sentry_sdk.init. We recently had a incident; dur... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | roy-work |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width