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!
In my case I had a continuous deployment pipeline setup and forgot to commit and push the
appengine_config.py
file. Double check that that file is available.Furthermore, to further configure the appstats module, refer to the file that is available in the appengine sdk source code:
/google_appengine/google/appengine/ext/appstats/sample_appengine_config.py
This is it
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: