Skip to content

docs(litestar): Document failed_request_status_codes #12604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/platforms/python/integrations/litestar/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,40 @@ When you point your browser to [http://localhost:8000/hello](http://localhost:80

It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).

## Options

By adding `LitestarIntegration` to your `sentry_sdk.init()` call explicitly, you can set options for `LitestarIntegration` to change its behavior:

```python
import sentry_sdk
from sentry_sdk.integrations.litestar import LitestarIntegration

sentry_sdk.init(
# ...
integrations=[
LitestarIntegration(
failed_request_status_codes={403, *range(500, 599)},
),
],
)
```

You can pass the following keyword arguments to `LitestarIntegration()`:

### `failed_request_status_codes`

A `set` of integers that will determine when an `HTTPException` should be reported to Sentry. The `HTTPException` is reported to Sentry if its status code is contained in the `failed_request_status_codes` set.

Examples of valid `failed_request_status_codes`:

- `{500}` will only report `HTTPException` with status 500.
- `{400, *range(500, 600)}` will report `HTTPException` with status 400 as well as those in the 5xx range.
- `set()` (the empty set) will not report any `HTTPException` to Sentry.

The default is `{*range(500, 600)}`, meaning that any `HTTPException` with a status in the 5xx range is reported to Sentry.

Regardless of how `failed_request_status_codes` is set, any exceptions raised by the handler, which are not of type `HTTPException` (or a subclass) are reported to Sentry. For example, if your request handler raises an unhandled `AttributeError`, the `AttributeError` gets reported to Sentry, even if you have set `failed_request_status_codes=set()`.

## Supported Versions

<Alert level="warning" title="Note">
Expand Down
Loading