Flask SDK doesn't see errors outside of requests

I’m not sure if I’m doing something wrong or if this is by design, but I can’t get the Flask SDK to capture “normal” python errors.

What I mean by “normal” is - not ones originating from some Flask route being hit externally (those work fine), but original internally from the app itself.

Simplest example:

sentry_sdk.init(
        dsn=os.environ.get("SENTRY_DSN"),
        integrations=[FlaskIntegration()],
    )

app = Flask(__name__)

raise Exception('im INVISIBLE!') #not seen

@app.route('/')
def hello():
    raise Exception('sentry can see me!') #seen correctly
    return "Hello World!"

if __name__ == '__main__':
    app.run()

If this normal? If so, how do I capture both types?

Which WSGI server are you using? is the problem occurring when executing this file on its own (i.e. devserver)?

I tried both using flask’s dev server (flask run) and using gunicorn. Both successfully initialize sentry before erroring out, but the error doesn’t appear in sentry.

Just a thought, could this be related to using:

pip install --upgrade 'sentry-sdk[flask]'

instead of just:

pip install --upgrade 'sentry-sdk'

I’m not familiar with the former syntax, so I might be off.

can you try using python app.py or something like that?

as for the syntax difference in pip install: the former just instructs pip to install blinker, which is an optional flask dependency that we need for signals to work. If you’re interested in the details read up on extras_require in setup.py