-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: Getting Started flask (#7861)
* Python: Getting Started flask * style(lint): Auto commit lint changes * Apply suggestions from code review Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com> --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com>
- Loading branch information
1 parent
e00886f
commit 1f3886c
Showing
6 changed files
with
112 additions
and
48 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
src/platform-includes/getting-started-config/python.flask.mdx
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
src/platform-includes/getting-started-install/python.flask.mdx
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
src/platform-includes/getting-started-primer/python.flask.mdx
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
src/platform-includes/getting-started-verify/python.flask.mdx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
<SignInNote /> | ||
|
||
```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__) | ||
``` | ||
|
||
<Note> | ||
|
||
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. | ||
|
||
</Note> | ||
|
||
## 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 "<p>Hello, World!</p>" | ||
``` | ||
|
||
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/<foo>") | ||
def myendpoint(): | ||
return "<p>Hello, World!</p>" | ||
``` | ||
|
||
In the above code, you would set the transaction to: | ||
|
||
- `/myurl/<foo>` 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+) |
1f3886c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sentry-docs – ./
sentry-docs-git-master.sentry.dev
sentry-docs.sentry.dev
docs.sentry.io