diff --git a/api.py b/api.py index f1f5cb39dd07b72b2c1a1859321bd90a8951b6a2..9fac4909b8bd270acc5571e88f680045d503e86c 100644 --- a/api.py +++ b/api.py @@ -115,6 +115,10 @@ def dispatcher(router, request, response): response.write(json.dumps(rv, default=bson.json_util.default)) response.headers['Content-Type'] = 'application/json; charset=utf-8' +try: + import newrelic.agent + app = newrelic.agent.WSGIApplicationWrapper(webapp2.WSGIApplication(routes)) +except ImportError: + app = webapp2.WSGIApplication(routes) -app = webapp2.WSGIApplication(routes) app.router.set_dispatcher(dispatcher) diff --git a/api.wsgi b/api.wsgi index 65b8abe68235a7e63ff1d7c93803159c8cf5e4a0..6a4a35c34f979e6cec79b0dc4e0133083a37d322 100644 --- a/api.wsgi +++ b/api.wsgi @@ -9,6 +9,15 @@ logging.basicConfig( log = logging.getLogger('scitran.api') logging.getLogger('scitran.data').setLevel(logging.WARNING) # silence scitran.data logging +try: + import newrelic.agent + newrelic.agent.initialize('../../newrelic.ini') + log.info('New Relic detected and loaded. Monitoring enabled.') +except ImportError: + log.info('New Relic not detected. Monitoring disabled.') +except newrelic.api.exceptions.ConfigurationError: + log.warn('New Relic detected but configuration was not valid. Please ensure newrelic.ini is present. Monitoring disabled.') + import os import time import pymongo