This makes a couple of changes:
- Most importantly, it wraps the setup code in a conditional so that
developers don't need to have a DSN set to start the app locally.
- Secondly, it removes the redundant call to "set_level". Originally
I thought the integration was sending info/warning events, but this
isn't the case [1] and even if it was, "set_level" affects the level
of custom events [2], not the level they are dispatched at.
[1]: 4c09f3203d/sentry_sdk/integrations/logging.py (L56)
[2]: https://docs.sentry.io/platforms/python/guides/logging/usage/set-level/
Otherwise we start spamming Sentry with every 404 error log. Even
if the erorr is a 5xx, it depends on how we handle it in the calling
code as to whether we would want to consider it an error.
I didn't spot this in initial testing on Preview because the 404s in
Preview are only triggered due to the functional tests, which only run
when we're deploying something.
Arguably we shouldn't be logging at error level in our Python Client,
since we're also raising an exception [1]. But changing that would be
a can of worms as it's not an internal-only library.
[1]: 74a958de00/notifications_python_client/base.py (L118)
This will capture and send various events to Sentry:
- Any unhandled exceptions.
- Any logger.error calls.
- Some request traces.
The latter are severely limited to avoid going over the free tier
limits for Sentry, and to avoid excess effort on our end.
We’re now serving assets from S3 when running on PaaS. So we’ll set
the appropriate caching headers there or in Cloudfront. This means that
the app no longer needs to serve cache headers, which is what we were
using WhiteNoise for.
This commits removes WhiteNoise in favour of letting Flask handle the
serving of static assets.
This is what Gunicorn is looking for when it’s running the app.
Renaming this variable to `app` has caused the app to break once
deployed on PaaS.
This commit also renames `app` to `flask_app` to make it clear which
app is wrapping which other app.
Since we version our asset filenames there’s no need for a browser to
ever fetch the same file twice. It should always cache fetch from its
own cache.
The accepted way to effect this behaviour is using the expires header,
which is what this argument to `WhiteNoise` does.
We're now running our app as a wsgi app locally, so don't need to
distinguish between the two processes by having wsgi and application.py
whitenoise just serves static files nicely - we don't lose anything
by doing that locally.
flask-script has been deprecated by the internal flask.cli module, but
making this carries a few changes with it
* you should add FLASK_APP=application.py and FLASK_DEBUG=1 to your
environment.sh.
* instead of using `python app.py runserver`, now you must run
`flask run -p 6012`. The -p command is important - the port must be
set before the config is loaded, so that it can live reload nicely.
(https://github.com/pallets/flask/issues/2113#issuecomment-268014481)
* find available commands by just running `flask`.
* run them using flask. eg `flask list_routes`
* define new tasks by giving them the decorator
`@app.cli.command('task-name')`. Task name isn't needed if it's just
the same as the function name. Alternatively, if app isn't available
in the current scope, you can invoke the decorator directly, as seen
in app/commands.py