Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"before_send_metric": Optional[Callable[[Metric, Hint], Optional[Metric]]],
"trace_lifecycle": Optional[Literal["static", "stream"]],
"ignore_spans": Optional[IgnoreSpansConfig],
"suppress_asgi_chained_exceptions": Optional[bool],

Check warning on line 87 in sentry_sdk/consts.py

View check run for this annotation

@sentry/warden / warden: code-review

No test coverage for new suppress_asgi_chained_exceptions experimental option

The new `suppress_asgi_chained_exceptions` experimental option lacks test coverage. The skill guidelines state every PR should have functional tests for business logic. This option controls whether chained exceptions are suppressed (the `raise exc from None` behavior), which is a behavioral change that should be tested for both `True` and `False` values to ensure the feature works correctly.
},
total=False,
)
Expand Down
33 changes: 29 additions & 4 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Based on Tom Christie's `sentry-asgi <https://github.com/encode/sentry-asgi>`.
"""

import sys
import asyncio
import inspect
from copy import deepcopy
Expand Down Expand Up @@ -37,6 +38,8 @@
logger,
transaction_from_function,
_get_installed_modules,
reraise,
capture_internal_exceptions,
)

from typing import TYPE_CHECKING
Expand Down Expand Up @@ -187,8 +190,19 @@
return await self.app(scope, receive, send)

except Exception as exc:
self._capture_lifespan_exception(exc)
raise exc from None
suppress_chained_exceptions = (
sentry_sdk.get_client()
.options.get("_experiments", {})
.get("suppress_asgi_chained_exceptions", True)
)
if suppress_chained_exceptions:
self._capture_lifespan_exception(exc)
raise exc from None

exc_info = sys.exc_info()
with capture_internal_exceptions():
self._capture_lifespan_exception(exc)
reraise(*exc_info)

Check warning on line 205 in sentry_sdk/integrations/asgi.py

View check run for this annotation

@sentry/warden / warden: code-review

[SG4-SLR] No test coverage for new suppress_asgi_chained_exceptions experimental option (additional location)

The new `suppress_asgi_chained_exceptions` experimental option lacks test coverage. The skill guidelines state every PR should have functional tests for business logic. This option controls whether chained exceptions are suppressed (the `raise exc from None` behavior), which is a behavioral change that should be tested for both `True` and `False` values to ensure the feature works correctly.

client = sentry_sdk.get_client()
span_streaming = has_span_streaming_enabled(client.options)
Expand Down Expand Up @@ -323,8 +337,19 @@
scope, receive, _sentry_wrapped_send
)
except Exception as exc:
self._capture_request_exception(exc)
raise exc from None
suppress_chained_exceptions = (
sentry_sdk.get_client()
.options.get("_experiments", {})
.get("suppress_asgi_chained_exceptions", True)
)
if suppress_chained_exceptions:
self._capture_request_exception(exc)
raise exc from None

exc_info = sys.exc_info()
with capture_internal_exceptions():
self._capture_request_exception(exc)
reraise(*exc_info)

Check warning on line 352 in sentry_sdk/integrations/asgi.py

View check run for this annotation

@sentry/warden / warden: code-review

[SG4-SLR] No test coverage for new suppress_asgi_chained_exceptions experimental option (additional location)

The new `suppress_asgi_chained_exceptions` experimental option lacks test coverage. The skill guidelines state every PR should have functional tests for business logic. This option controls whether chained exceptions are suppressed (the `raise exc from None` behavior), which is a behavioral change that should be tested for both `True` and `False` values to ensure the feature works correctly.
finally:
_asgi_middleware_applied.set(False)

Expand Down
Loading