Skip to content

Commit e8ab62d

Browse files
docs(python): Document sys.exit integration (#11153)
* docs(python): Document sys.exit integration Add documentation for the sys.exit integration, introduced in getsentry/sentry-python#3401. Closes #11043 * Apply suggestions from code review Co-authored-by: vivianyentran <[email protected]> --------- Co-authored-by: vivianyentran <[email protected]>
1 parent 36750b0 commit e8ab62d

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

docs/platforms/python/integrations/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
110110
| <LinkWithPlatformIcon platform="python.pure_eval" label="Enhanced Locals" url="/platforms/python/integrations/pure_eval" /> | |
111111
| <LinkWithPlatformIcon platform="python.gnu_backtrace" label="GNU Backtrace" url="/platforms/python/integrations/gnu_backtrace" /> | |
112112
| <LinkWithPlatformIcon platform="python.socket" label="Socket" url="/platforms/python/integrations/socket" /> | |
113+
| <LinkWithPlatformIcon platform="python.sys_exit" label="sys.exit" url="/platforms/python/integrations/sys_exit" /> | |
113114
| <LinkWithPlatformIcon platform="python.tryton" label="Tryton" url="/platforms/python/integrations/tryton" /> | |
114115
| <LinkWithPlatformIcon platform="python.wsgi" label="WSGI" url="/platforms/python/integrations/wsgi" /> | |
115116

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: sys.exit
3+
description: Learn how to use Sentry to capture sys.exit calls.
4+
---
5+
6+
The `SysExitIntegration` records `sys.exit` calls by capturing the `SystemExit` exception raised by `sys.exit`.
7+
8+
## Install
9+
10+
```bash
11+
pip install --upgrade "sentry-sdk"
12+
```
13+
14+
## Configure
15+
16+
The `SysExitIntegration` is disabled by default, and the SDK only captures `SystemExit` exceptions automatically if this integration is manually enabled.
17+
18+
A `sys.exit` call is considered "successful" when the function is passed a value of `0` or `None`. Passing any other value results in an "unsuccessful" exit.
19+
20+
To enable the `SysExitIntegration` and configure it to only capture unsuccessful `sys.exit` calls, use the following:
21+
22+
<SignInNote />
23+
24+
```python
25+
import sentry_sdk
26+
from sentry_sdk.integrations.sys_exit import SysExitIntegration
27+
28+
sentry_sdk.init(
29+
dsn="___PUBLIC_DSN___",
30+
integrations=[SysExitIntegration()],
31+
)
32+
```
33+
34+
If you wish to capture successful and unsuccessful `sys.exit` calls, use the following, instead:
35+
36+
```python
37+
import sentry_sdk
38+
from sentry_sdk.integrations.sys_exit import SysExitIntegration
39+
40+
sentry_sdk.init(
41+
dsn="___PUBLIC_DSN___",
42+
integrations=[SysExitIntegration(capture_successful_exits=True)],
43+
)
44+
```
45+
46+
47+
48+
## Verify
49+
50+
Running the following snippet should result in a `SystemExit` exception being reported to Sentry.
51+
52+
```python
53+
import sys
54+
55+
import sentry_sdk
56+
from sentry_sdk.integrations.sys_exit import SysExitIntegration
57+
58+
sentry_sdk.init(
59+
dsn="___PUBLIC_DSN___",
60+
integrations=[SysExitIntegration()],
61+
)
62+
63+
sys.exit(1)
64+
```
65+
66+
If you use `capture_successful_exits=True`, calling `sys.exit(0)` should also report a `SystemExit` exception to Sentry.
67+
68+
69+
<Alert level="info" title="Manually-raised SystemExit">
70+
71+
Please note that the `SysExitIntegration` only captures `SystemExit` exceptions which are raised by calling `sys.exit`. If your code raises `SystemExit` without calling `sys.exit`, the exception will not be reported to Sentry.
72+
73+
</Alert>

0 commit comments

Comments
 (0)