From 0776a8f6290500fccfc2e56f28939c269db035ae Mon Sep 17 00:00:00 2001 From: inventarSarah Date: Thu, 3 Sep 2026 12:13:14 +0200 Subject: [PATCH 1/6] update Flask quick start guide --- .../python/integrations/flask/index.mdx | 176 +++++++++++++----- ...quick-start-verify-tracing-splitlayout.mdx | 6 + 2 files changed, 140 insertions(+), 42 deletions(-) diff --git a/docs/platforms/python/integrations/flask/index.mdx b/docs/platforms/python/integrations/flask/index.mdx index c712e44c2f590..a25aafd231b5e 100644 --- a/docs/platforms/python/integrations/flask/index.mdx +++ b/docs/platforms/python/integrations/flask/index.mdx @@ -1,39 +1,101 @@ --- title: Flask -description: "Learn about using Sentry with Flask." +description: "Learn how to set up Sentry in your Flask app, capture your first errors and traces, and view them in Sentry." --- -The Flask integration adds support for the [Flask Web Framework](https://flask.palletsprojects.com). - -## Install +## Prerequisites -Install `sentry-sdk` from PyPI: +You need: -```bash {tabTitle:pip} -pip install sentry-sdk -``` +- A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/) +- Your application up and running +- Flask `1.1.4+` +- Python `3.6+` -```bash {tabTitle:uv} -uv add sentry-sdk -``` + + +## Install + + ## Configure -If you have the `flask` package in your dependencies, the Flask integration will be enabled automatically when you initialize the Sentry SDK. +Choose the features you want to configure, and this guide will show you how: + + + + - +### Initialize the Sentry SDK + +Configuration should happen as **early as possible** in your application's lifecycle. -Our Python SDK will install the Flask integration for all of your apps. It hooks into Flask’s signals, not anything on the app object. +If you have the `flask` package in your dependencies, the Flask integration will be enabled and installed for all your apps automatically when you initialize the Sentry SDK. +The SDK hooks into Flask's signals, not anything on the app object. -## Verify + + + + +Import and initialize the SDK in your app's entry point: + + + + + + + + + + +To further customize your setup, review the [Options section](#options) below. + +### Capturing Errors + +Sentry automatically captures errors and reports issues for you. +You can also expect the following for your Django project: + +- If you use `flask-login`, and you've set `send_default_pii=True` in your call to `init`, user data (such as current user ID, email address, username) will be attached to error events. +- Request data will be attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. +- Logs emitted by any `app.logger` or _any_ logger will be recorded by the [Logging](/platforms/python/integrations/logging/) integration (this integration is enabled by default). + + + + + + + +## Verify Your Setup + +Let's test your setup and confirm that data reaches your Sentry project. + + + +### Issues + + + + + +To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application: + + + + ```python +import sentry_sdk from flask import Flask sentry_sdk.init(...) # same as above @@ -46,25 +108,39 @@ def hello_world(): return "

Hello, World!

" ``` -When you point your browser to [http://localhost:5000/](http://localhost:5000/) a transaction in the Performance section of [sentry.io](https://sentry.io) will be created. Additionally, an error event will be sent to [sentry.io](https://sentry.io) and will be connected to the transaction. +
+
+
-It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io). + -## Behavior + - + + + + + + + -After initialization: + -- If you use `flask-login` and set `send_default_pii=True` in your call to `init`, user data (current user id, email address, username) will be attached to the event. -- Request data will be attached to all events: **HTTP method, URL, headers, form data, JSON payloads**. Sentry excludes raw bodies and multipart file uploads. -- Logs emitted by `app.logger` or _any_ logger will be recorded as breadcrumbs by the [Logging](/platforms/python/integrations/logging/) integration (this integration is enabled by default). + + + + +### View Captured Data in Sentry + +Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). + + ## Options -If you add `FlaskIntegration` explicitly to your `sentry_sdk.init()` call you can set options for `FlaskIntegration` to change its behavior: +Add `FlaskIntegration` explicitly to your `sentry_sdk.init()` call to set options for `FlaskIntegration` to change its behavior: ```python import sentry_sdk @@ -83,37 +159,53 @@ sentry_sdk.init( You can pass the following keyword arguments to `FlaskIntegration()`: -- `transaction_style`: + + +How to name transactions that show up in Sentry tracing. +The default is `"url"`. + + + + - Sets the format or style that transactions are named. +In the code example, the transaction name will be: -
+ - `/myurl/` if you set `transaction_style="url"` + - `myendpoint` if you set `transaction_style="endpoint"` - ```python +
+ + +```python @app.route("/myurl/") def myendpoint(): return "

Hello, World!

" - ``` +``` + +
+
+
+ +
- In the above code, you would set the transaction to: - - `/myurl/` if you set `transaction_style="url"`. - - `myendpoint` if you set `transaction_style="endpoint"`. + - The default is `"endpoint"`. +A tuple containing all the HTTP methods (as uppercase strings) that should create a transaction in Sentry. +The default is `("CONNECT", "DELETE", "GET", "PATCH", "POST", "PUT", "TRACE",)`. -- `http_methods_to_capture`: +Note that `OPTIONS` and `HEAD` are excluded by default. - A tuple containing all the HTTP methods that should create a transaction in Sentry. + - The default is `("CONNECT", "DELETE", "GET", "PATCH", "POST", "PUT", "TRACE",)`. +## Next Steps - (Note that `OPTIONS` and `HEAD` are missing by default.) + - The `http_methods_to_capture` option. + -## Supported Versions +- Find various topics in Troubleshooting +- [Get support](https://www.sentry.help/en/) -- Flask: 1.1.4+ -- Python: 3.6+ + - +
diff --git a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx index 9eb6f0698eff2..6b38c72cae7d7 100644 --- a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx +++ b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx @@ -15,6 +15,12 @@ import sentry_sdk with sentry_sdk.start_transaction(op="task", name="Transaction Name"): span = sentry_sdk.start_span(name="Custom Span Name") span.finish() + +# or, when using stream mode: +# with sentry_sdk.traces.start_span(name="Transaction Name", attributes={"sentry.op": "task"}): +# with sentry_sdk.traces.start_span(name="Custom Span Name") as span: +# ... + ``` From a9114c80a92766263937b109008322274e1f4895 Mon Sep 17 00:00:00 2001 From: inventarSarah Date: Thu, 3 Sep 2026 12:18:32 +0200 Subject: [PATCH 2/6] add tab for stream mode tracing test snippet --- ...ython-quick-start-verify-tracing-splitlayout.mdx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx index 6b38c72cae7d7..0d1c8fb13aa9f 100644 --- a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx +++ b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx @@ -9,17 +9,20 @@ To test your tracing configuration, create a custom transaction and span: -```py +```py {tabTitle: Transaction Mode (Default)} import sentry_sdk with sentry_sdk.start_transaction(op="task", name="Transaction Name"): span = sentry_sdk.start_span(name="Custom Span Name") span.finish() -# or, when using stream mode: -# with sentry_sdk.traces.start_span(name="Transaction Name", attributes={"sentry.op": "task"}): -# with sentry_sdk.traces.start_span(name="Custom Span Name") as span: -# ... +``` +```py {tabTitle: Stream Mode} +import sentry_sdk + + with sentry_sdk.traces.start_span(name="Transaction Name", attributes={"sentry.op": "task"}): + with sentry_sdk.traces.start_span(name="Custom Span Name") as span: + ... ``` From 6caae503f8c821cd41266495a6a06ded971c5a3d Mon Sep 17 00:00:00 2001 From: inventarSarah Date: Thu, 3 Sep 2026 13:01:46 +0200 Subject: [PATCH 3/6] pr review feedback --- docs/platforms/python/integrations/flask/index.mdx | 4 ++-- .../python-quick-start-verify-tracing-splitlayout.mdx | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/platforms/python/integrations/flask/index.mdx b/docs/platforms/python/integrations/flask/index.mdx index a25aafd231b5e..a7d275ead458f 100644 --- a/docs/platforms/python/integrations/flask/index.mdx +++ b/docs/platforms/python/integrations/flask/index.mdx @@ -64,7 +64,7 @@ To further customize your setup, review the [Options section](#options) below. ### Capturing Errors Sentry automatically captures errors and reports issues for you. -You can also expect the following for your Django project: +You can also expect the following for your Flask app: - If you use `flask-login`, and you've set `send_default_pii=True` in your call to `init`, user data (such as current user ID, email address, username) will be attached to error events. - Request data will be attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. @@ -162,7 +162,7 @@ You can pass the following keyword arguments to `FlaskIntegration()`: How to name transactions that show up in Sentry tracing. -The default is `"url"`. +The default is `"endpoint"`. diff --git a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx index 0d1c8fb13aa9f..7f18d52988ecd 100644 --- a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx +++ b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx @@ -20,9 +20,9 @@ with sentry_sdk.start_transaction(op="task", name="Transaction Name"): ```py {tabTitle: Stream Mode} import sentry_sdk - with sentry_sdk.traces.start_span(name="Transaction Name", attributes={"sentry.op": "task"}): - with sentry_sdk.traces.start_span(name="Custom Span Name") as span: - ... +with sentry_sdk.traces.start_span(name="Transaction Name", attributes={"sentry.op": "task"}): + with sentry_sdk.traces.start_span(name="Custom Span Name") as span: + ... ``` From 06aa21b610ab8c1c411f324be222367d0232c164 Mon Sep 17 00:00:00 2001 From: inventarSarah Date: Thu, 3 Sep 2026 13:05:56 +0200 Subject: [PATCH 4/6] pr review feedback --- docs/platforms/python/integrations/flask/index.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/platforms/python/integrations/flask/index.mdx b/docs/platforms/python/integrations/flask/index.mdx index a7d275ead458f..403f562684b8f 100644 --- a/docs/platforms/python/integrations/flask/index.mdx +++ b/docs/platforms/python/integrations/flask/index.mdx @@ -177,9 +177,9 @@ In the code example, the transaction name will be: ```python - @app.route("/myurl/") - def myendpoint(): - return "

Hello, World!

" + @app.route("/myurl/") + def myendpoint(): + return "

Hello, World!

" ```
From 83fc24ec0e0a2890804ef8a40c385e459a0f6422 Mon Sep 17 00:00:00 2001 From: Sarah Mischinger Date: Tue, 15 Sep 2026 09:34:45 +0000 Subject: [PATCH 5/6] Apply batched suggestions from code review PR review feedback Co-authored-by: Ivana Kellyer --- .../python-quick-start-verify-tracing-splitlayout.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx index 7f18d52988ecd..4f34c12308310 100644 --- a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx +++ b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx @@ -20,9 +20,9 @@ with sentry_sdk.start_transaction(op="task", name="Transaction Name"): ```py {tabTitle: Stream Mode} import sentry_sdk -with sentry_sdk.traces.start_span(name="Transaction Name", attributes={"sentry.op": "task"}): - with sentry_sdk.traces.start_span(name="Custom Span Name") as span: - ... +with sentry_sdk.traces.start_span(name="Service Span Name", attributes={"sentry.op": "task"}): + span = sentry_sdk.traces.start_span(name="Custom Span Name") + span.end() ``` From 5c431688be78e1ccfa73661a58c86e9ef04838f6 Mon Sep 17 00:00:00 2001 From: inventarSarah Date: Tue, 15 Sep 2026 11:40:38 +0200 Subject: [PATCH 6/6] fix link --- docs/platforms/python/integrations/celery/index.mdx | 10 +--------- .../python-quick-start-verify-tracing-splitlayout.mdx | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/docs/platforms/python/integrations/celery/index.mdx b/docs/platforms/python/integrations/celery/index.mdx index 1ba477f882b93..8e48fa449ab45 100644 --- a/docs/platforms/python/integrations/celery/index.mdx +++ b/docs/platforms/python/integrations/celery/index.mdx @@ -338,15 +338,7 @@ See Celery Beat Auto Discovery

customize your configuration
-- Learn more about manually capturing errors or messages -- Dive straight into the API with our [API docs](https://getsentry.github.io/sentry-python/) + diff --git a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx index 4f34c12308310..c5d51b293bb28 100644 --- a/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx +++ b/includes/tracing/python-quick-start-verify-tracing-splitlayout.mdx @@ -20,7 +20,7 @@ with sentry_sdk.start_transaction(op="task", name="Transaction Name"): ```py {tabTitle: Stream Mode} import sentry_sdk -with sentry_sdk.traces.start_span(name="Service Span Name", attributes={"sentry.op": "task"}): +with sentry_sdk.traces.start_span(name="Service Span Name", attributes={"sentry.op": "task"}, parent_span=None): span = sentry_sdk.traces.start_span(name="Custom Span Name") span.end()