|
27 | 27 | # Python 3.10 and below |
28 | 28 | BaseExceptionGroup = None # type: ignore |
29 | 29 |
|
30 | | -try: |
31 | | - from aiohttp.web_exceptions import HTTPException as AIOHttpHttpException |
32 | | -except ImportError: |
33 | | - AIOHttpHttpException = None |
34 | | - |
35 | 30 | from typing import TYPE_CHECKING |
36 | 31 |
|
37 | 32 | import sentry_sdk |
|
93 | 88 | "is_sentry_internal_task", default=False |
94 | 89 | ) |
95 | 90 |
|
| 91 | +# These exceptions won't set the span status to error if they occur. Use |
| 92 | +# register_control_flow_exception to add to this list |
| 93 | +_control_flow_exceptions = [] |
| 94 | + |
96 | 95 |
|
97 | 96 | def is_internal_task() -> bool: |
98 | 97 | return _is_sentry_internal_task.get() |
@@ -1983,15 +1982,16 @@ def get_current_thread_meta( |
1983 | 1982 | return None, None |
1984 | 1983 |
|
1985 | 1984 |
|
| 1985 | +def register_control_flow_exception(exc_type: type) -> None: |
| 1986 | + _control_flow_exceptions.append(exc_type) |
| 1987 | + |
| 1988 | + |
1986 | 1989 | def should_be_treated_as_error(ty: "Any", value: "Any") -> bool: |
1987 | 1990 | if ty == SystemExit and hasattr(value, "code") and value.code in (0, None): |
1988 | 1991 | # https://docs.python.org/3/library/exceptions.html#SystemExit |
1989 | 1992 | return False |
1990 | 1993 |
|
1991 | | - # In the aiohttp integration, all of their HTTP responses are Exceptions. |
1992 | | - # Because they have to be raised and handled by the framework, we need this check so |
1993 | | - # that we don't accidentally overwrite a status of "ok" with "error" here. |
1994 | | - if AIOHttpHttpException and isinstance(value, AIOHttpHttpException): |
| 1994 | + if ty in _control_flow_exceptions: |
1995 | 1995 | return False |
1996 | 1996 |
|
1997 | 1997 | return True |
|
0 commit comments