##// END OF EJS Templates
exception_tracker: store request info if available.
marcink -
r4301:9712e26b default
parent child Browse files
Show More
@@ -34,7 +34,7 b" global_prefix = 'rhodecode'"
34 34 exc_store_dir_name = 'rc_exception_store_v1'
35 35
36 36
37 def exc_serialize(exc_id, tb, exc_type):
37 def exc_serialize(exc_id, tb, exc_type, extra_data=None):
38 38
39 39 data = {
40 40 'version': 'v1',
@@ -44,6 +44,8 b' def exc_serialize(exc_id, tb, exc_type):'
44 44 'exc_message': tb,
45 45 'exc_type': exc_type,
46 46 }
47 if extra_data:
48 data.update(extra_data)
47 49 return msgpack.packb(data), data
48 50
49 51
@@ -80,10 +82,20 b' def _store_exception(exc_id, exc_type_na'
80 82 """
81 83 Low level function to store exception in the exception tracker
82 84 """
85 from pyramid.threadlocal import get_current_request
83 86 import rhodecode as app
87 request = get_current_request()
88 extra_data = {}
89 # NOTE(marcink): store request information into exc_data
90 if request:
91 extra_data['client_address'] = getattr(request, 'client_addr', '')
92 extra_data['user_agent'] = getattr(request, 'user_agent', '')
93 extra_data['method'] = getattr(request, 'method', '')
94 extra_data['url'] = getattr(request, 'url', '')
84 95
85 96 exc_store_path = get_exc_store()
86 exc_data, org_data = exc_serialize(exc_id, exc_traceback, exc_type_name)
97 exc_data, org_data = exc_serialize(exc_id, exc_traceback, exc_type_name, extra_data=extra_data)
98
87 99 exc_pref_id = '{}_{}_{}'.format(exc_id, prefix, org_data['exc_timestamp'])
88 100 if not os.path.isdir(exc_store_path):
89 101 os.makedirs(exc_store_path)
@@ -100,23 +112,20 b' def _store_exception(exc_id, exc_type_na'
100 112 send_email = send_email and mail_server
101 113 if send_email:
102 114 try:
103 send_exc_email(exc_id, exc_type_name)
115 send_exc_email(request, exc_id, exc_type_name)
104 116 except Exception:
105 117 log.exception('Failed to send exception email')
106 118 pass
107 119
108 120
109 def send_exc_email(exc_id, exc_type_name):
121 def send_exc_email(request, exc_id, exc_type_name):
110 122 import rhodecode as app
111 from pyramid.threadlocal import get_current_request
112 123 from rhodecode.apps._base import TemplateArgs
113 124 from rhodecode.lib.utils2 import aslist
114 125 from rhodecode.lib.celerylib import run_task, tasks
115 126 from rhodecode.lib.base import attach_context_attributes
116 127 from rhodecode.model.notification import EmailNotificationModel
117 128
118 request = get_current_request()
119
120 129 recipients = aslist(app.CONFIG.get('exception_tracker.send_email_recipients', ''))
121 130 log.debug('Sending Email exception to: `%s`', recipients or 'all super admins')
122 131
@@ -6,8 +6,17 b''
6 6 % if c.traceback:
7 7
8 8 <h4>${_('Exception `{}` generated on UTC date: {}').format(c.traceback.get('exc_type', 'NO_TYPE'), c.traceback.get('exc_utc_date', 'NO_DATE'))}</h4>
9 % if c.traceback.get('url'):
10 Request:
11 <code>${c.traceback.get('method')} ${c.traceback.get('url')}</code><br/>
12 <code>${c.traceback.get('client_address')} ${c.traceback.get('user_agent')}</code>
13 <br/>
14 <br/>
15 % endif
16
9 17 <pre>${c.traceback.get('exc_message', 'NO_MESSAGE')}</pre>
10 18
19
11 20 % else:
12 21 ${_('Unable to Read Exception. It might be removed or non-existing.')}
13 22 % endif
General Comments 0
You need to be logged in to leave comments. Login now