Logging exceptions prevent responses on App Engine with Flask
See original GitHub issueI have what I expect is the quintessential setup with Google App Engine + Flask + Raven, so I would expect this to be a common problem.
The issue is that when one calls e.g. logging.error
with Raven capturing logging the Flask endpoint never completes. It just hangs. Example for reproduction is below.
I did a little debugging and Flask, for its part, seems to finish its wsgi_app
requests as expected, so the problem seems to be with Google App Engine.
I am running OS X 10.11.6, App Engine 1.9.38 development app server via homebrew.
Steps to reproduce (minimum working example)
mkdir ae-sentry
cd ae-sentry
virtualenv pyve
./pyve/bin/pip install raven[flask]
Then create:
appengine_config.py
from os import path
from google.appengine.ext import vendor
vendor.add(path.abspath(path.join(path.dirname(__file__), 'pyve')))
app.yaml
application: dummy
version: test
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: app.app
libraries:
- name: ssl
version: latest
app.py
import sys
import logging
sys.path.insert(0, 'pyve')
from flask import Flask, make_response
from raven.contrib.flask import Sentry
app = Flask('test')
sentry = Sentry(app, logging=True, level=logging.ERROR)
# Note, we get SENTRY_DSN from environment
@app.route('/')
def test():
# Comment the following logging.exception and the endpoint works.
# Uncomment it, and it never completes.
# logging.exception("Boo!")
return make_response("ok")
Finally, reproduce at will with dev_appserver.py .
and opening localhost:8080
in a browser.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to log uncaught exceptions in Flask routes with logging?
To demonstrate how logging uncaught exceptions in Flask routes works, let's create a simple Flask app that has two routes: one that returns...
Read more >Application Errors — Flask Documentation (0.12.x)
By default if your application runs in production mode, Flask will display a very simple page for you and log the exception to...
Read more >Reading and Writing Application Logs - Python 2 - Google Cloud
logging.exception('A example exception log.') self.response.out.write('Logging example.') app = webapp2.WSGIApplication([ ('/', MainPage) ], debug=True) ...
Read more >How To Handle Errors in a Flask Application - DigitalOcean
app.logger.critical() : A critical error; the entire application might stop working. To demonstrate how to use the Flask logger, open your ...
Read more >Developing Python Web Applications with Flask
You can stop the server by pressing Ctrl-C . Run the webapp (Since Flask 0.11). Starting from Flask 0.11, there is a new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am still having problem with this. I have:
raven[flask]==5.32.0
I am receiving the report in sentry, but my end point is hanging when the exception is sent. The endpoint is fine if captureException isn’t called. Is there something I am missing?
I think what we should do here is one of two things: