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
1=== modified file 'linaro_django_xmlrpc/models.py'
2--- linaro_django_xmlrpc/models.py 2011-08-17 02:50:25 +0000
3+++ linaro_django_xmlrpc/models.py 2012-02-09 02:12:18 +0000
4@@ -283,7 +283,7 @@
5 obj = cls(context)
6 except:
7 # TODO: Perhaps this should be an APPLICATION_ERROR?
8- logging.exception("unable to instantiate stuff")
9+ logging.exception("unable to instantiate API class %r", cls)
10 meth = getattr(obj, meth_name, None)
11 if not inspect.ismethod(meth):
12 return
13@@ -346,6 +346,7 @@
14 def __init__(self, mapper, allow_none=True):
15 self.mapper = mapper
16 self.allow_none = allow_none
17+ self.logger = logging.getLogger("linaro_django_xmlrcp.models.Dispatcher")
18
19 def decode_request(self, data):
20 """
21@@ -399,6 +400,9 @@
22 try:
23 impl = self.mapper.lookup(method_name, context)
24 if impl is None:
25+ self.logger.error(
26+ 'Unable to dispatch unknown method %r', method_name,
27+ extra={'request': context.request})
28 raise xmlrpclib.Fault(
29 FaultCodes.ServerError.REQUESTED_METHOD_NOT_FOUND,
30 "No such method: %r" % method_name)
31@@ -408,22 +412,27 @@
32 # Forward XML-RPC Faults to the client
33 raise
34 except:
35- # Treat all other exceptions as internal errors
36- self.handle_internal_error(method_name, params)
37+ # Call a helper than can do more
38+ if self.handle_internal_error(method_name, params) is None:
39+ # If there is no better handler we should log the problem
40+ self.logger.error(
41+ "Internal error in the XML-RPC dispatcher while calling method %r with %r",
42+ method_name, params, exc_info=True,
43+ extra={'request': context.request})
44+ # TODO: figure out a way to get the error id from Raven if that is around
45 raise xmlrpclib.Fault(
46 FaultCodes.ServerError.INTERNAL_XML_RPC_ERROR,
47- "Internal Server Error (details hidden)")
48+ "Internal Server Error (details hidden :)")
49
50 def handle_internal_error(self, method_name, params):
51 """
52 Handle exceptions raised while dispatching registered methods.
53
54- Subclasses may implement this but cannot prevent the
55- xmlrpclib.Fault from being raised.
56+ Subclasses may implement this but cannot prevent the xmlrpclib.Fault
57+ from being raised. If something other than None is returned then a
58+ logging message will be supressed.
59 """
60- logging.exception(
61- "Unable to dispatch XML-RPC method %s(%s)",
62- method_name, params)
63+ return None
64
65
66 class SystemAPI(ExposedAPI):

Subscribers

People subscribed via source and target branches