Skip to content
Myr

Update sentry error handling documentation (#2990)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Change examples to use the Sentry Python SDK: `sentry-sdk` - Removed the app factory pattern example - Added a custom exception handling example

authored by Adam Walsh · committed by Markus Unterwaditzer · parent e08bcf9 · Browse files · 1 file+23 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−20 removed

  • other:+23 added−20 removed

1 file+23 added−20 removed

modified:docs/errorhandling.rst+23 added-20 removed
32 unmodified lines
3334Sending error mails, even if just for critical ones, can become35overwhelming if enough users are hitting the error and log files are36typically never looked at. This is why we recommend using `Sentry37<https://www.getsentry.com/>`_ for dealing with application errors. It's37<https://sentry.io/>`_ for dealing with application errors. It's38available as an Open Source project `on GitHub39<https://github.com/getsentry/sentry>`__ and is also available as a `hosted version40<https://getsentry.com/signup/>`_ which you can try for free. Sentry39<https://github.com/getsentry/sentry>`_ and is also available as a `hosted version40<https://sentry.io/signup/>`_ which you can try for free. Sentry41aggregates duplicate errors, captures the full stack trace and local42variables for debugging, and sends you mails based on new errors or43frequency thresholds.4445To use Sentry you need to install the `raven` client with extra `flask` dependencies::45To use Sentry you need to install the `sentry-sdk` client with extra `flask` dependencies::4647 $ pip install raven[flask]47 $ pip install sentry-sdk[flask]4849And then add this to your Flask app::5051 from raven.contrib.flask import Sentry52 sentry = Sentry(app, dsn='YOUR_DSN_HERE')51 import sentry_sdk52 from sentry_sdk.integrations.flask import FlaskIntegration53 54 sentry_sdk.init('YOUR_DSN_HERE',integrations=[FlaskIntegration()])5554Or if you are using factories you can also init it later::5556 from raven.contrib.flask import Sentry57 sentry = Sentry(dsn='YOUR_DSN_HERE')5859 def create_app():60 app = Flask(__name__)61 sentry.init_app(app)62 ...63 return app6456The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get57from your Sentry installation.5868Afterwards failures are automatically reported to Sentry and from there69you can receive error notifications.59After installation, failures leading to an Internal Server Error are automatically reported to 60Sentry and from there you can receive error notifications. Sentry also supports 61capturing custom exceptions::62 63 import sentry_sdk64 65 try:66 throwing_function()67 except Exception as e:68 with sentry_sdk.push_scope() as scope:69 sentry_sdk.capture_exception(e)7071See the `Python <https://docs.sentry.io/platforms/python/>`_ and `Flask-specific <https://docs.sentry.io/platforms/python/flask/>`_ 72Sentry SDK documentation for more detailed information.7374.. _error-handlers:7576Error handlers77--------------
141 unmodified lines