Skip to content

Commit

Permalink
docs(python): Document sys.exit integration
Browse files Browse the repository at this point in the history
Add documentation for the sys.exit integration, introduced in getsentry/sentry-python#3401.

Closes #11043
  • Loading branch information
szokeasaurusrex committed Aug 27, 2024
1 parent c8fa1e0 commit 1e18ba9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/platforms/python/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
| <LinkWithPlatformIcon platform="python.pure_eval" label="Enhanced Locals" url="/platforms/python/integrations/pure_eval" /> | |
| <LinkWithPlatformIcon platform="python.gnu_backtrace" label="GNU Backtrace" url="/platforms/python/integrations/gnu_backtrace" /> | |
| <LinkWithPlatformIcon platform="python.socket" label="Socket" url="/platforms/python/integrations/socket" /> | |
| <LinkWithPlatformIcon platform="python.sys_exit" label="sys.exit" url="/platforms/python/integrations/sys_exit" /> | |
| <LinkWithPlatformIcon platform="python.tryton" label="Tryton" url="/platforms/python/integrations/tryton" /> | |
| <LinkWithPlatformIcon platform="python.wsgi" label="WSGI" url="/platforms/python/integrations/wsgi" /> | |

Expand Down
72 changes: 72 additions & 0 deletions docs/platforms/python/integrations/sys_exit/index.mdx
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>

0 comments on commit 1e18ba9

Please sign in to comment.