I’d like to stop Sentry from reporting errors that are happening on my laptop during development.
I’d usually use the Flask app’s env property to detect whether I’m in development or production. However, the Sentry client is set up before the app is created.
Is there a recommended way to disable Sentry for development when using Flask?
Hi,
- You can run
sentry_sdk.init()
without arguments again to disable the SDK completely. Your capture_exception
calls will become no-ops.
- You do not have to run
init()
before creating the Flask app. You can run it almost anywhere during import time.
With that being said I would recommend keeping the SDK enabled in development mode, but with a few changes:
from __future__ import print_function
app = Flask(__name__)
if app.debug:
init(transport=print)
else:
# production init
So you can already see in development which events would be sent to sentry, and how they look like. You could probably make a function that prints the event (a simple JSON-serializable dictionary) print a bit less (and more nicely), but I think you get the general idea.
1 Like
That solution looks perfect. Thank you!