-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(python): Document sys.exit integration
Add documentation for the sys.exit integration, introduced in getsentry/sentry-python#3401. Closes #11043
- Loading branch information
1 parent
c8fa1e0
commit 1e18ba9
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
title: sys.exit | ||
description: Learn how to use Sentry to capture sys.exit calls | ||
--- | ||
|
||
The `SysExitIntegration` records `sys.exit` calls by capturing the `SystemExit` exception raised by `sys.exit`. | ||
|
||
## Install | ||
|
||
```bash | ||
pip install --upgrade "sentry-sdk" | ||
``` | ||
|
||
## Configure | ||
|
||
The `SysExitIntegration` is disabled by default, and the SDK only captures `SystemExit` exceptions automatically if this integration is manually enabled. | ||
|
||
To enable the `SysExitIntegration` and configure it to only capture unsuccessful `sys.exit` calls, use the following: | ||
|
||
<SignInNote /> | ||
|
||
```python | ||
import sentry_sdk | ||
from sentry_sdk.integrations.sys_exit import SysExitIntegration | ||
|
||
sentry_sdk.init( | ||
dsn="___PUBLIC_DSN___", | ||
integrations=[SysExitIntegration()], | ||
) | ||
``` | ||
|
||
If you wish to capture successful and unsuccessful `sys.exit` calls, use the following, instead: | ||
|
||
```python | ||
import sentry_sdk | ||
from sentry_sdk.integrations.sys_exit import SysExitIntegration | ||
|
||
sentry_sdk.init( | ||
dsn="___PUBLIC_DSN___", | ||
integrations=[SysExitIntegration(capture_successful_exits=True)], | ||
) | ||
``` | ||
|
||
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. | ||
|
||
|
||
## Verify | ||
|
||
Running the following snippet should result in a `SystemExit` exception being reported to Sentry. | ||
|
||
```python | ||
import sys | ||
|
||
import sentry_sdk | ||
from sentry_sdk.integrations.sys_exit import SysExitIntegration | ||
|
||
sentry_sdk.init( | ||
dsn="___PUBLIC_DSN___", | ||
integrations=[SysExitIntegration()], | ||
) | ||
|
||
sys.exit(1) | ||
``` | ||
|
||
If you use `capture_successful_exits=True`, calling `sys.exit(0)` should also report a `SystemExit` exception to Sentry. | ||
|
||
|
||
<Alert level="info" title="Manually-raised SystemExit"> | ||
|
||
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. | ||
|
||
</Alert> |