question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logging exceptions prevent responses on App Engine with Flask

See original GitHub issue

I 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)

  1. mkdir ae-sentry
  2. cd ae-sentry
  3. virtualenv pyve
  4. ./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:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jmgirvencommented, Dec 8, 2016

I am still having problem with this. I have:

raven[flask]==5.32.0

from raven.contrib.flask import Sentry
sentry = Sentry(app, dsn="...")
sentry.captureException(data={...})

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?

1reaction
dcramercommented, Jul 30, 2016

I think what we should do here is one of two things:

  1. sentry-python-appengine which contains the transport/etc and configures defaults differently
  2. ensure we have a fully compatible appengine transport in core, and feature detect to use it as a default in these situations.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found