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 ...@@ -19,7 +19,6 @@ from lxml import etree
from module_render import render_module, make_track_function, I4xSystem from module_render import render_module, make_track_function, I4xSystem
from models import StudentModule from models import StudentModule
from student.models import UserProfile from student.models import UserProfile
from util.errors import record_exception
from util.views import accepts from util.views import accepts
from multicourse import multicourse_settings from multicourse import multicourse_settings
...@@ -114,7 +113,7 @@ def render_section(request, section): ...@@ -114,7 +113,7 @@ def render_section(request, section):
try: try:
dom = content_parser.section_file(user, section, coursename) dom = content_parser.section_file(user, section, coursename)
except: except:
record_exception(log, "Unable to parse courseware xml") log.exception("Unable to parse courseware xml")
return render_to_response('courseware-error.html', {}) return render_to_response('courseware-error.html', {})
context = { context = {
...@@ -133,7 +132,7 @@ def render_section(request, section): ...@@ -133,7 +132,7 @@ def render_section(request, section):
try: try:
module = render_module(user, request, dom, module_object_preload) module = render_module(user, request, dom, module_object_preload)
except: except:
record_exception(log, "Unable to load module") log.exception("Unable to load module")
context.update({ context.update({
'init': '', 'init': '',
'content': render_to_string("module-error.html", {}), 'content': render_to_string("module-error.html", {}),
...@@ -182,7 +181,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"): ...@@ -182,7 +181,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"):
try: try:
dom = content_parser.course_file(user,course) # also pass course to it, for course-specific XML path dom = content_parser.course_file(user,course) # also pass course to it, for course-specific XML path
except: except:
record_exception(log, "Unable to parse courseware xml") log.exception("Unable to parse courseware xml")
return render_to_response('courseware-error.html', {}) return render_to_response('courseware-error.html', {})
dom_module = dom.xpath("//course[@name=$course]/chapter[@name=$chapter]//section[@name=$section]/*[1]", 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"): ...@@ -211,7 +210,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"):
try: try:
module = render_module(user, request, module, module_object_preload) module = render_module(user, request, module, module_object_preload)
except: except:
record_exception(log, "Unable to load module") log.exception("Unable to load module")
context.update({ context.update({
'init': '', 'init': '',
'content': render_to_string("module-error.html", {}), 'content': render_to_string("module-error.html", {}),
...@@ -256,7 +255,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -256,7 +255,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
try: try:
xml = content_parser.module_xml(request.user, module, 'id', id, coursename) xml = content_parser.module_xml(request.user, module, 'id', id, coursename)
except: 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'): if accepts(request, 'text/html'):
return render_to_response("module-error.html", {}) return render_to_response("module-error.html", {})
else: else:
...@@ -276,7 +275,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -276,7 +275,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
id, id,
state=oldstate) state=oldstate)
except: 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'): if accepts(request, 'text/html'):
return render_to_response("module-error.html", {}) return render_to_response("module-error.html", {})
else: else:
......
...@@ -29,7 +29,7 @@ def get_logger_config(log_dir, ...@@ -29,7 +29,7 @@ def get_logger_config(log_dir,
" %(process)d] [%(filename)s:%(lineno)d] - %(message)s").format( " %(process)d] [%(filename)s:%(lineno)d] - %(message)s").format(
logging_env=logging_env, hostname=hostname) logging_env=logging_env, hostname=hostname)
handlers = ['console'] if debug else ['console', 'syslogger'] handlers = ['console'] if debug else ['console', 'syslogger', 'newrelic']
return { return {
'version': 1, 'version': 1,
...@@ -60,6 +60,11 @@ def get_logger_config(log_dir, ...@@ -60,6 +60,11 @@ def get_logger_config(log_dir,
'filename' : tracking_file_loc, 'filename' : tracking_file_loc,
'formatter' : 'raw', 'formatter' : 'raw',
}, },
'newrelic' : {
'level': 'ERROR',
'class': 'newrelic_logging.NewRelicHandler',
'formatter': 'raw',
}
}, },
'loggers' : { 'loggers' : {
'django' : { 'django' : {
...@@ -83,4 +88,4 @@ def get_logger_config(log_dir, ...@@ -83,4 +88,4 @@ def get_logger_config(log_dir,
'propagate' : False '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