Flask

Import name: sentry_sdk.integrations.flask.FlaskIntegration

The Flask integration adds support for the Flask Web Framework.

  1. Install sentry-sdk from PyPI with the flask extra:

     $ pip install --upgrade sentry-sdk[flask]==0.6.2
    
  2. To configure the SDK, initialize it with the integration before or after your app has been initialized:

    import sentry_sdk
    from sentry_sdk.integrations.flask import FlaskIntegration
    
    sentry_sdk.init(
        dsn="___PUBLIC_DSN___",
        integrations=[FlaskIntegration()]
    )
    
    app = Flask(__name__)
    

Behavior

  • The Flask integration will be installed for all of your apps. It hooks into Flaskā€™s signals, not anything on the app object.

  • All exceptions leading to a Internal Server Error are reported.

  • Request data is attached to all events: HTTP method, URL, headers, formdata, JSON payloads. Raw bodies and multipart file uploads are excluded. Personally identifiable information (such as user ids, usernames, cookies, authorization headers, ip addresses) is excluded unless send_default_pii is set to True.

  • 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.

  • Logging with app.logger or really any logger will create breadcrumbs when the Logging integration is enabled (done by default).

Options

The following keyword arguments can be passed to FlaskIntegration():

  • transaction_style:

    @app.route("/myurl/<foo>")
    def myendpoint():
        return "ok"
    

    In the above code, the transaction would be set to:

    • /myurl/<foo> if you set transaction_style="url". This matches the behavior of the old Raven SDK.
    • myendpoint if you set transaction_style="endpoint"

    The default is "endpoint".

User Feedback

The user feedback feature can be used with this integration. For more information see User Feedback.