Skip to content

Commit 1e18ba9

Browse files
docs(python): Document sys.exit integration
Add documentation for the sys.exit integration, introduced in getsentry/sentry-python#3401. Closes #11043
1 parent c8fa1e0 commit 1e18ba9

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
To enable the `SysExitIntegration` and configure it to only capture unsuccessful `sys.exit` calls, use the following:
19+
20+
<SignInNote />
21+
22+
```python
23+
import sentry_sdk
24+
from sentry_sdk.integrations.sys_exit import SysExitIntegration
25+
26+
sentry_sdk.init(
27+
dsn="___PUBLIC_DSN___",
28+
integrations=[SysExitIntegration()],
29+
)
30+
```
31+
32+
If you wish to capture successful and unsuccessful `sys.exit` calls, use the following, instead:
33+
34+
```python
35+
import sentry_sdk
36+
from sentry_sdk.integrations.sys_exit import SysExitIntegration
37+
38+
sentry_sdk.init(
39+
dsn="___PUBLIC_DSN___",
40+
integrations=[SysExitIntegration(capture_successful_exits=True)],
41+
)
42+
```
43+
44+
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.
45+
46+
47+
## Verify
48+
49+
Running the following snippet should result in a `SystemExit` exception being reported to Sentry.
50+
51+
```python
52+
import sys
53+
54+
import sentry_sdk
55+
from sentry_sdk.integrations.sys_exit import SysExitIntegration
56+
57+
sentry_sdk.init(
58+
dsn="___PUBLIC_DSN___",
59+
integrations=[SysExitIntegration()],
60+
)
61+
62+
sys.exit(1)
63+
```
64+
65+
If you use `capture_successful_exits=True`, calling `sys.exit(0)` should also report a `SystemExit` exception to Sentry.
66+
67+
68+
<Alert level="info" title="Manually-raised SystemExit">
69+
70+
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.
71+
72+
</Alert>

0 commit comments

Comments
 (0)