Skip to content
Snippets Groups Projects
Commit 1e531ac5 authored by Nathaniel Kofalt's avatar Nathaniel Kofalt
Browse files

Merge pull request #72 from scitran/newrelic

Allow for custom newrelic.ini path
parents 8989c5cd 845c5dc1
No related branches found
No related tags found
No related merge requests found
......@@ -129,10 +129,6 @@ def dispatcher(router, request, response):
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)
# vim: filetype=python
import os
import sys
import toml
import logging
import argparse
......@@ -19,6 +20,7 @@ ap.add_argument('--insecure', help='allow user info as urlencoded param', action
ap.add_argument('--central_uri', help='scitran central api', default='https://sdmc.scitran.io/api')
ap.add_argument('--log_level', help='log level [info]', default='info')
ap.add_argument('--drone_secret', help='shared drone secret')
ap.add_argument('--new_relic', help='path to New Relic .ini file')
ap.add_argument('--config', help='path to config file')
......@@ -73,15 +75,6 @@ from api import api
from api import centralclient, jobs
from api import jobs
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.')
log.setLevel(getattr(logging, args.log_level.upper()))
api.app.config = vars(args)
......@@ -102,6 +95,20 @@ if not os.path.exists(api.app.config['data_path']):
api.app.db = mongo.db
if args.new_relic is not None:
try:
import newrelic.agent, newrelic.api.exceptions
newrelic.agent.initialize(args.new_relic)
api.app = newrelic.agent.WSGIApplicationWrapper(api.app)
log.info('New Relic detected and loaded. Monitoring enabled.')
except ImportError:
log.critical('New Relic libraries not found.')
sys.exit(1)
except newrelic.api.exceptions.ConfigurationError:
log.critical('New Relic detected, but configuration invalid.')
sys.exit(1)
if __name__ == '__main__':
api.app.debug = True # send stack trace for uncaught exceptions to client
paste.httpserver.serve(api.app, host=args.host, port=args.port, ssl_pem=args.ssl_cert)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment