loading before all modules and defer to middleware

18 views
Skip to first unread message

Guillermo Cruz

unread,
Feb 6, 2012, 11:16:58 PM2/6/12
to pylons-...@googlegroups.com
Hi,

 I'm trying to configure an app monitoring agent on a Pylons app, so the recommended setup is to initialize the agent before all modules import, and also  create a middleware class to collect stats on each request. I have the following setup working but there's the potential risk for the monitoring agent being initialized twice and the agent not working as intended. Any pointers on how to take a better approach?.


import newrelic.agent

#class in config/middleware.py

class NewRelicAgent(object):
    def __init__(self, app):
        self.app = app
        newrelic.agent.initialize('/path/to/file/newrelic.ini')

    @newrelic.agent.wsgi_application()
    def __call__(self, environ, start_response):
        return self.app(environ, start_response)

#config/middleware.py make_app def 

app = NewRelicAgent(app)

cd34

unread,
Feb 7, 2012, 1:18:46 AM2/7/12
to pylons-discuss
Matthew Housden documented this on his blog:

http://matthewhousden.com/python/new-relic-and-pyramid/

basically:

import newrelic.agent
newrelic.agent.initialize('path/to/newrelic.ini', 'development')

application = config.make_wsgi_app()
return newrelic.agent.wsgi_application()(application)
Reply all
Reply to author
Forward
0 new messages