Merge lp:~zyga/linaro-django-xmlrpc/better-sentry-support into lp:~linaro-validation/linaro-django-xmlrpc/trunk

Proposed by Zygmunt Krynicki
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 43
Merged at revision: 43
Proposed branch: lp:~zyga/linaro-django-xmlrpc/better-sentry-support
Merge into: lp:~linaro-validation/linaro-django-xmlrpc/trunk
Diff against target: 66 lines (+18/-9)
1 file modified
linaro_django_xmlrpc/models.py (+18/-9)
To merge this branch: bzr merge lp:~zyga/linaro-django-xmlrpc/better-sentry-support
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+92179@code.launchpad.net

Description of the change

A few simple changes for better integration with Sentry. Tested locally with an
apache/uwsgi installation.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

+1

As said on IRC, including an oops id in the response to an unhandled internal error would be great, but that doesn't have to happen today.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro_django_xmlrpc/models.py'
--- linaro_django_xmlrpc/models.py 2011-08-17 02:50:25 +0000
+++ linaro_django_xmlrpc/models.py 2012-02-09 02:12:18 +0000
@@ -283,7 +283,7 @@
283 obj = cls(context)283 obj = cls(context)
284 except:284 except:
285 # TODO: Perhaps this should be an APPLICATION_ERROR?285 # TODO: Perhaps this should be an APPLICATION_ERROR?
286 logging.exception("unable to instantiate stuff")286 logging.exception("unable to instantiate API class %r", cls)
287 meth = getattr(obj, meth_name, None)287 meth = getattr(obj, meth_name, None)
288 if not inspect.ismethod(meth):288 if not inspect.ismethod(meth):
289 return289 return
@@ -346,6 +346,7 @@
346 def __init__(self, mapper, allow_none=True):346 def __init__(self, mapper, allow_none=True):
347 self.mapper = mapper347 self.mapper = mapper
348 self.allow_none = allow_none348 self.allow_none = allow_none
349 self.logger = logging.getLogger("linaro_django_xmlrcp.models.Dispatcher")
349350
350 def decode_request(self, data):351 def decode_request(self, data):
351 """352 """
@@ -399,6 +400,9 @@
399 try:400 try:
400 impl = self.mapper.lookup(method_name, context)401 impl = self.mapper.lookup(method_name, context)
401 if impl is None:402 if impl is None:
403 self.logger.error(
404 'Unable to dispatch unknown method %r', method_name,
405 extra={'request': context.request})
402 raise xmlrpclib.Fault(406 raise xmlrpclib.Fault(
403 FaultCodes.ServerError.REQUESTED_METHOD_NOT_FOUND,407 FaultCodes.ServerError.REQUESTED_METHOD_NOT_FOUND,
404 "No such method: %r" % method_name)408 "No such method: %r" % method_name)
@@ -408,22 +412,27 @@
408 # Forward XML-RPC Faults to the client412 # Forward XML-RPC Faults to the client
409 raise413 raise
410 except:414 except:
411 # Treat all other exceptions as internal errors415 # Call a helper than can do more
412 self.handle_internal_error(method_name, params)416 if self.handle_internal_error(method_name, params) is None:
417 # If there is no better handler we should log the problem
418 self.logger.error(
419 "Internal error in the XML-RPC dispatcher while calling method %r with %r",
420 method_name, params, exc_info=True,
421 extra={'request': context.request})
422 # TODO: figure out a way to get the error id from Raven if that is around
413 raise xmlrpclib.Fault(423 raise xmlrpclib.Fault(
414 FaultCodes.ServerError.INTERNAL_XML_RPC_ERROR,424 FaultCodes.ServerError.INTERNAL_XML_RPC_ERROR,
415 "Internal Server Error (details hidden)")425 "Internal Server Error (details hidden :)")
416426
417 def handle_internal_error(self, method_name, params):427 def handle_internal_error(self, method_name, params):
418 """428 """
419 Handle exceptions raised while dispatching registered methods.429 Handle exceptions raised while dispatching registered methods.
420430
421 Subclasses may implement this but cannot prevent the431 Subclasses may implement this but cannot prevent the xmlrpclib.Fault
422 xmlrpclib.Fault from being raised.432 from being raised. If something other than None is returned then a
433 logging message will be supressed.
423 """434 """
424 logging.exception(435 return None
425 "Unable to dispatch XML-RPC method %s(%s)",
426 method_name, params)
427436
428437
429class SystemAPI(ExposedAPI):438class SystemAPI(ExposedAPI):

Subscribers

People subscribed via source and target branches