I'm using App Engine python to host an application and would love to use Appstats and a couple of other libraries that run as middleware. However, when I set up middleware through appengine_config.py (as shown below) it works on the dev server but not in production. Appstats AND gaesessions work like a charm in the dev server and don't work at all in production. Here is my appengine_config.py, located in my root /src dir:
from com.impactpy.gaesessions import SessionMiddleware
COOKIE_KEY = 'nice try'
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats import recording
app = SessionMiddleware(app, cookie_key=COOKIE_KEY)
app = recording.appstats_wsgi_middleware(app)
return app
Any ideas?
UPDATE
So I'm bringing this back up as I've tried again to fix it to no avail. I've boiled appengine_config.py down to:
from google.appengine.ext.appstats import recording
def webapp_add_wsgi_middleware(app):
app = recording.appstats_wsgi_middleware(app)
return app
and app.yaml includes
builtins:
- datastore_admin: on
- remote_api: on
- appstats: on
My app uses basic webapp, bottom of every request-handling file includes:
application = webapp.WSGIApplication( [
('/handler', myHandlerClass)
],debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Deploying works fine. App has been going strong for over a year and sees lots of requests. myapp.appspot.com/_ah/stats comes up showing the GUI with a refresh button, no data, and the message "No requests have been recorded yet" etc. I'm confused!
I think the problem is how you import SessionMiddleware. Try to put gaesessions at the top level of your project directory.
Here is an appengine_config.py
I used successfully:
from gaesessions import SessionMiddleware
from google.appengine.ext.appstats import recording
def webapp_add_wsgi_middleware(app):
app = SessionMiddleware(app, cookie_key="s3cr3t")
app = recording.appstats_wsgi_middleware(app)
return app