Help With Python, uWSGI and New Relic

I've used New Relic in the past for PHP projects, but I am now trying to use it on a new server for a Python project. The extent of my linux server administration experience is I was able to follow this tutorial to setup the server and get everything working for uWSGI: https://library.linode.com/web-servers/ … e-pangolin">https://library.linode.com/web-servers/nginx/python-uwsgi/ubuntu-12.04-precise-pangolin

However, I am struggling to setup New Relic's uWSGI integration using their documentation (https://docs.newrelic.com/docs/python/p … -and-uwsgi">https://docs.newrelic.com/docs/python/python-agent-and-uwsgi). Their instructions point to configuration and startup files that I didn't have to modify (thanks to the great linode documentation), so I'm not really sure where to go from here or what to do next.

Has anyone else use New Relic with uWSGI and can point me in the right direction?

2 Replies

I use uWSGI with New Relic. I don't use their wrapper script or anything like that, just the wsgi_application wrapper function. So, I do something like this in my wsgi.py module:

from django.core.wsgi import get_wsgi_application

newrelic_ini = 'path/to/newrelic.ini'

try:
    import newrelic.agent
except:
    application = get_wsgi_application()
else:
    newrelic.agent.initialize(newrelic_ini, 'production')
    @newrelic.agent.wsgi_application()
    def application(environ, start_response):
        _application = get_wsgi_application()
        return _application(environ, start_response)

I do the try/except thing so that I can use the same wsgi.py on dev machines without New Relic.

Thanks, worked like a charm!

I'm using Bottlepy as my web app framework, so I just needed to do the following:

newrelic_ini = '/newrelic.ini'

try:
    import newrelic.agent

    newrelic.agent.initialize(newrelic_ini, 'production')

    application = newrelic.agent.WSGIApplicationWrapper(bottle.default_app())

except:
    print 'newrelic agent not found... continuing anyways'
    application = bottle.default_app()

Note: I had to follow the instructions here (http://www.julianbez.com/blog/2013/07/2 … -pangolin/">http://www.julianbez.com/blog/2013/07/23/update-uwsgi-to-the-latest-version-on-ubuntu-12-04-lts-precise-pangolin/) in order to get the latest version of uWSGI in order for the New Relic Python Agent to work. apt-get only gives you version 1.0.3 which is not supported. I then had to update my .xml config file in the /etc/uwsgi/apps-available directory to replace deprecated config options:

Replaced

 <app mountpoint="/"></app> 

with

<module>wsgi_configuration_module</module>

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct