diff --git a/src/platform-includes/getting-started-config/python.flask.mdx b/src/platform-includes/getting-started-config/python.flask.mdx deleted file mode 100644 index a97d01e665234..0000000000000 --- a/src/platform-includes/getting-started-config/python.flask.mdx +++ /dev/null @@ -1,23 +0,0 @@ - - -```python -import sentry_sdk -from flask import Flask - -sentry_sdk.init( - dsn="___PUBLIC_DSN___", - - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for performance monitoring. - # We recommend adjusting this value in production. - traces_sample_rate=1.0, - - # By default the SDK will try to use the SENTRY_RELEASE - # environment variable, or infer a git commit - # SHA as release, however you may want to set - # something more human-readable. - # release="myapp@1.0.0", -) - -app = Flask(__name__) -``` diff --git a/src/platform-includes/getting-started-install/python.flask.mdx b/src/platform-includes/getting-started-install/python.flask.mdx deleted file mode 100644 index c9e56c3f4f04b..0000000000000 --- a/src/platform-includes/getting-started-install/python.flask.mdx +++ /dev/null @@ -1,5 +0,0 @@ -Install `sentry-sdk` from PyPI with the `flask` extra: - -```bash -pip install --upgrade 'sentry-sdk[flask]' -``` diff --git a/src/platform-includes/getting-started-primer/python.flask.mdx b/src/platform-includes/getting-started-primer/python.flask.mdx deleted file mode 100644 index 30ef372a0bd42..0000000000000 --- a/src/platform-includes/getting-started-primer/python.flask.mdx +++ /dev/null @@ -1,5 +0,0 @@ - - -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. Each request has a separate scope. Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request being handled. - - diff --git a/src/platform-includes/getting-started-verify/python.flask.mdx b/src/platform-includes/getting-started-verify/python.flask.mdx deleted file mode 100644 index cf823e375b369..0000000000000 --- a/src/platform-includes/getting-started-verify/python.flask.mdx +++ /dev/null @@ -1,11 +0,0 @@ -```python -@app.route('/debug-sentry') -def trigger_error(): - division_by_zero = 1 / 0 -``` - -After initialization: - -- If you use `flask-login` and have set `send_default_pii=True` in your call to `init`, user data (current user id, email address, username) is attached to the event. -- Request data is 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 are recorded as breadcrumbs by the [Logging](/platforms/python/guides/logging/) integration (this integration is enabled by default). diff --git a/src/platforms/python/guides/flask/config.yml b/src/platforms/python/guides/flask/config.yml deleted file mode 100644 index 61d0168917cd4..0000000000000 --- a/src/platforms/python/guides/flask/config.yml +++ /dev/null @@ -1,4 +0,0 @@ -title: Flask -caseStyle: snake_case -supportLevel: production -sdk: sentry.python.flask diff --git a/src/platforms/python/guides/flask/index.mdx b/src/platforms/python/guides/flask/index.mdx new file mode 100644 index 0000000000000..2a3098259b309 --- /dev/null +++ b/src/platforms/python/guides/flask/index.mdx @@ -0,0 +1,112 @@ +--- +title: Flask +redirect_from: + - /platforms/python/flask/ +description: "Learn about using Sentry with Flask." +--- + +The Flask integration adds support for the [Flask Web Framework](https://flask.palletsprojects.com). + +## Install + +Install `sentry-sdk` from PyPI with the `flask` extra: + +```bash +pip install --upgrade "sentry-sdk[flask]" +``` + +## Configure + +If you have the `flask` package in your dependencies, the Flask integration will be enabled automatically when you initialize the Sentry SDK. + + + +```python +from flask import Flask +import sentry_sdk + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + traces_sample_rate=1.0, +) + +app = Flask(__name__) +``` + + + +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. + + + +## Verify + +```python +from flask import Flask + +sentry_sdk.init(...) # same as above + +app = Flask(__name__) + +@app.route("/") +def hello_world(): + 1/0 # raises an error + 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/guides/logging/) integration (this integration is enabled by default). + +## Options + +If you add `FlaskIntegration` explicitly to your `sentry_sdk.init()` call you can set options for `FlaskIntegration` to change its behavior: + +```python +import sentry_sdk +from sentry_sdk.integrations.flask import FlaskIntegration + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + traces_sample_rate=1.0, + integrations = [ + FlaskIntegration( + transaction_style="url", + ), + ], +) +``` + +You can pass the following keyword arguments to `FlaskIntegration()`: + +- `transaction_style`: + + ```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"`. + +## Supported Versions + +- Flask: 0.11+ +- Python: 2.7+ (Flask 0.11+), 3.6 (Flask 2.0+)