Search code examples
djangouwsginewrelic

How to test a python eval statement in UWSGI application's ini config?


As far I can tell, my eval statement within a USWGI's app config isn't working/executing, but I cannot figure out how to test this.

  • OS: Debian GNU/Linux 7.1 (wheezy)
  • UWSGI: 1.2.3-debian
  • Python: 2.7

I'm actually trying to setup Newrelic's application monitoring with the following in my app.ini file (using the application mounting method for a Django app):

[uwsgi]
chdir = /home/app-user/myapp/bin
wsgi-file = django.wsgi
socket = 127.0.0.1:3031
pythonpath = /home/app-user/myapp/src
logto = /var/log/uwsgi/app/myapp.log
enable-threads = true
single-interpreter = true
eval = import newrelic.agent, django.wsgi; newrelic.agent.initialize('/path/to/newrelic.ini'); application = newrelic.agent.wsgi_application()(django.wsgi.application)

My newrelic.ini conf:

log_file = /tmp/newrelic-python-agent.log

After restarting and making some requests to the app (which is up and running as per usual) the newrelic log_file is not even created, and there is nothing in the uwsgi app log or the django log, so I don't know how to tell what is happening in the eval.

I've tried putting outright syntactically incorrect stuff in the eval, but uwsgi still restarts successfully.

Is there a way to validate what's in the eval statement as executed by the uwsgi process?


Solution

  • I'm late to the party, but your problem was that you had wsgi-file option that made eval useless. (Same goes for module option - this is the case I had.)

    So, to make uWSGI wrap any WSGI application with a middleware, you just had to remove the offending options. I.e.:

    ; DON'T USE THIS: wsgi-file=myproject/wsgi.py
    ; NEITHER THIS: module=myproject.wsgi
    eval=import myproject.wsgi, myfancymw; application = myfancymw.wrap(myproject.wsgi.application)