2

I'm trying to get Appstats to work on my GAE Python app. I'm using webapp2 with python 2.7.

I've followed the instructions from https://developers.google.com/appengine/docs/python/tools/appstats#Setup which includes creating the appengine_config.py file:

def webapp_add_wsgi_middleware(app):
    from google.appengine.ext.appstats import recording
    app = recording.appstats_wsgi_middleware(app)
    return app

And adding the following lines to my app.yaml:

builtins:
- appstats: on

The python app I wish to use Appstats on looks something like this:

import webapp2
from google.appengine.api import urlfetch
from google.appengine.ext import db
import appengine_config

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello word!')

app = webapp2.WSGIApplication([
    webapp2.Route(r'/method1/', handler=Method1, name='method1'),
    webapp2.Route(r'/method2/', handler=Method2, name='method2'),
    webapp2.Route(r'/', handler=MainHandler, name='home')
], debug=True)

(I tried import appengine_config after reading the comments from Appstats are only working for one WSGIApplication but that doesn't work neither)

The problem I'm facing is that I can see the appstats console at /_ah/stats but it is not recording anything even after many requests have been made to the app.

I'm wondering if it has anything to do with the fact that I'm using extended URL routes? I'd really like to use webapps2 extended routing, so I hope Appstats doesn't have issues with it. If anyone has any insights on what I'm doing wrong, it will really help!

Thanks loads in advance!

Community
  • 1
  • 1
jedimdan
  • 58
  • 5

2 Answers2

2

Maybe this will help:

1) I only configured in my app.yaml:

builtins:
- appstats: on

2) And the appengine_config.py :

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

def webapp_add_wsgi_middleware(app):                    
    from google.appengine.ext.appstats import recording
    app = recording.appstats_wsgi_middleware(app)
    return app

3) I did not have to change my handlers or routing.

voscausa
  • 11,253
  • 2
  • 39
  • 67
  • Thanks for your answer! I think you misunderstood, the routing and handlers were for my application. So I guess my question should be how to get Appstats to work with this handler and routing. – jedimdan Dec 11 '12 at 02:59
  • No I did not misunderstand your question. Or still do. You do not have too change your handler code. It does not affect appstats. – voscausa Dec 11 '12 at 10:03
  • I guess I have trouble understanding your answer because it looks identical to my existing code. I tried adding `from __future__ import unicode_literals` to the top of my appengine_config.py like you did, but still no change. – jedimdan Dec 11 '12 at 10:45
  • from __future__ import unicode_literals does not affect the code. If you use the same appengine_config.py I do not understand why it does not work. – voscausa Dec 11 '12 at 12:03
0

After much investigation, it turned out that the answer to my problem was a careless mistake. I had somehow created the appengine_config.py file in a sub folder, rather than the root folder, and I didn't notice it because I had been using an IDE.

So should anyone have this problem, make sure:

  1. appengine_config.py is in the root folder
  2. appengine_config.py contains the code mentioned above
  3. app.yaml contains the appstats: on as a builtins: (If you can access /_ah/stats, this part is configured properly)

And it should work. :)

jedimdan
  • 58
  • 5