From 71680dbed58a2ed47ca5d2a7cca58382411fb9b6 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Wed, 5 Jun 2024 11:44:30 +0200 Subject: [PATCH] feat(python): Add failed_request_status_codes to integrations --- .../python/integrations/fastapi/index.mdx | 21 ++++++++++++++++--- .../python/integrations/starlette/index.mdx | 16 +++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/platforms/python/integrations/fastapi/index.mdx b/docs/platforms/python/integrations/fastapi/index.mdx index 3108d695df22f..6fe18cc5f5b1f 100644 --- a/docs/platforms/python/integrations/fastapi/index.mdx +++ b/docs/platforms/python/integrations/fastapi/index.mdx @@ -43,7 +43,7 @@ It takes a couple of moments for the data to appear in [sentry.io](https://sentr The following information about your FastAPI project will be available to you on Sentry.io: -- All exceptions leading to an Internal Server Error are captured and reported. +- By default, all exceptions leading to an Internal Server Error are captured and reported. The HTTP status codes to report on are configurable via the `failed_request_status_codes` [option](#options). - Request data such as URL, HTTP method, headers, form data, and JSON payloads is attached to all issues. - Sentry excludes raw bodies and multipart file uploads. - Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set `send_default_pii` to `True`. @@ -80,10 +80,12 @@ sentry_sdk.init( # same as above integrations=[ StarletteIntegration( - transaction_style="endpoint" + transaction_style="endpoint", + failed_request_status_codes=[403, range(500, 599)], ), FastApiIntegration( - transaction_style="endpoint" + transaction_style="endpoint", + failed_request_status_codes=[403, range(500, 599)], ), ] ) @@ -126,6 +128,19 @@ You can pass the following keyword arguments to `StarletteIntegration()` and `Fa The default is `"url"`. +- `failed_request_status_codes`: + + A list of integers or containers (objects that allow membership checks via `in`) + of integers that will determine which status codes should be reported to Sentry. + + Examples of valid `failed_request_status_codes`: + + - `[500]` will only send events on HTTP 500. + - `[400, range(500, 599)]` will send events on HTTP 400 as well as the 500-599 range. + - `[500, 503]` will send events on HTTP 500 and 503. + + The default is `[range(500, 599)]`. + ## Supported Versions - FastAPI: 0.79.0+ diff --git a/docs/platforms/python/integrations/starlette/index.mdx b/docs/platforms/python/integrations/starlette/index.mdx index 781649bf97ad9..738fe220268fc 100644 --- a/docs/platforms/python/integrations/starlette/index.mdx +++ b/docs/platforms/python/integrations/starlette/index.mdx @@ -41,7 +41,7 @@ It takes a couple of moments for the data to appear in [sentry.io](https://sentr ## Behavior -- All exceptions leading to an Internal Server Error are reported. +- By default, all exceptions leading to an Internal Server Error are reported. The HTTP status codes to report on are configurable via the `failed_request_status_codes` [option](#options). - Request data is attached to all events: **HTTP method, URL, headers, form data, JSON payloads**. Sentry excludes raw bodies and multipart file uploads. Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set `send_default_pii` to `True`. @@ -59,6 +59,7 @@ sentry_sdk.init( integrations=[ StarletteIntegration( transaction_style="endpoint", + failed_request_status_codes=[403, range(500, 599)], ) ], ) @@ -84,6 +85,19 @@ You can pass the following keyword arguments to `StarletteIntegration()`: The default is `"url"`. +- `failed_request_status_codes`: + + A list of integers or containers (objects that allow membership checks via `in`) + of integers that will determine which status codes should be reported to Sentry. + + Examples of valid `failed_request_status_codes`: + + - `[500]` will only send events on HTTP 500. + - `[400, range(500, 599)]` will send events on HTTP 400 as well as the 500-599 range. + - `[500, 503]` will send events on HTTP 500 and 503. + + The default is `[range(500, 599)]`. + ## Supported Versions - Starlette: 0.19.1+