Commit 03a9be7e by Calen Pennington

Add newrelic handler, rather than custom function to log exceptions

parent 4fe22be5
......@@ -19,7 +19,6 @@ from lxml import etree
from module_render import render_module, make_track_function, I4xSystem
from models import StudentModule
from student.models import UserProfile
from util.errors import record_exception
from util.views import accepts
from multicourse import multicourse_settings
......@@ -114,7 +113,7 @@ def render_section(request, section):
try:
dom = content_parser.section_file(user, section, coursename)
except:
record_exception(log, "Unable to parse courseware xml")
log.exception("Unable to parse courseware xml")
return render_to_response('courseware-error.html', {})
context = {
......@@ -133,7 +132,7 @@ def render_section(request, section):
try:
module = render_module(user, request, dom, module_object_preload)
except:
record_exception(log, "Unable to load module")
log.exception("Unable to load module")
context.update({
'init': '',
'content': render_to_string("module-error.html", {}),
......@@ -182,7 +181,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"):
try:
dom = content_parser.course_file(user,course) # also pass course to it, for course-specific XML path
except:
record_exception(log, "Unable to parse courseware xml")
log.exception("Unable to parse courseware xml")
return render_to_response('courseware-error.html', {})
dom_module = dom.xpath("//course[@name=$course]/chapter[@name=$chapter]//section[@name=$section]/*[1]",
......@@ -211,7 +210,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"):
try:
module = render_module(user, request, module, module_object_preload)
except:
record_exception(log, "Unable to load module")
log.exception("Unable to load module")
context.update({
'init': '',
'content': render_to_string("module-error.html", {}),
......@@ -256,7 +255,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
try:
xml = content_parser.module_xml(request.user, module, 'id', id, coursename)
except:
record_exception(log, "Unable to load module during ajax call")
log.exception("Unable to load module during ajax call")
if accepts(request, 'text/html'):
return render_to_response("module-error.html", {})
else:
......@@ -276,7 +275,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
id,
state=oldstate)
except:
record_exception(log, "Unable to load module instance during ajax call")
log.exception("Unable to load module instance during ajax call")
if accepts(request, 'text/html'):
return render_to_response("module-error.html", {})
else:
......
......@@ -29,7 +29,7 @@ def get_logger_config(log_dir,
" %(process)d] [%(filename)s:%(lineno)d] - %(message)s").format(
logging_env=logging_env, hostname=hostname)
handlers = ['console'] if debug else ['console', 'syslogger']
handlers = ['console'] if debug else ['console', 'syslogger', 'newrelic']
return {
'version': 1,
......@@ -60,6 +60,11 @@ def get_logger_config(log_dir,
'filename' : tracking_file_loc,
'formatter' : 'raw',
},
'newrelic' : {
'level': 'ERROR',
'class': 'newrelic_logging.NewRelicHandler',
'formatter': 'raw',
}
},
'loggers' : {
'django' : {
......@@ -83,4 +88,4 @@ def get_logger_config(log_dir,
'propagate' : False
},
}
}
\ No newline at end of file
}
import newrelic.agent
import logging
class NewRelicHandler(logging.Handler):
def emit(self, record):
if record.exc_info is not None:
params = record.__dict__
params['log_message'] = record.getMessage()
newrelic.agent.record_exception(
*record.exc_info,
params=params
)
import newrelic.agent
import sys
def record_exception(logger, msg, params={}, ignore_errors=[]):
logger.exception(msg)
newrelic.agent.record_exception(*sys.exc_info())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment