##// END OF EJS Templates
ae: Rely on fully prepared settings in appenlight wrapping function.
Martin Bornhold -
r594:71243b44 default
parent child Browse files
Show More
@@ -1,92 +1,91 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 """
21 """
22 middleware to handle appenlight publishing of errors
22 middleware to handle appenlight publishing of errors
23 """
23 """
24
24
25 from appenlight_client import make_appenlight_middleware
25 from appenlight_client import make_appenlight_middleware
26 from appenlight_client.exceptions import get_current_traceback
26 from appenlight_client.exceptions import get_current_traceback
27 from appenlight_client.wsgi import AppenlightWSGIWrapper
27 from appenlight_client.wsgi import AppenlightWSGIWrapper
28 from paste.deploy.converters import asbool
29
28
30
29
31 def track_exception(environ):
30 def track_exception(environ):
32 if 'appenlight.client' not in environ:
31 if 'appenlight.client' not in environ:
33 return
32 return
34
33
35 # pass the traceback object to middleware
34 # pass the traceback object to middleware
36 environ['appenlight.__traceback'] = get_current_traceback(
35 environ['appenlight.__traceback'] = get_current_traceback(
37 skip=1,
36 skip=1,
38 show_hidden_frames=True,
37 show_hidden_frames=True,
39 ignore_system_exceptions=True)
38 ignore_system_exceptions=True)
40
39
41
40
42 def track_extra_information(environ, section, value):
41 def track_extra_information(environ, section, value):
43 """
42 """
44 Utility function to attach extra information in case of an error condition.
43 Utility function to attach extra information in case of an error condition.
45
44
46 It will take care of attaching this information to the right place inside
45 It will take care of attaching this information to the right place inside
47 of `environ`, so that the appenight client can pick it up.
46 of `environ`, so that the appenight client can pick it up.
48 """
47 """
49 environ.setdefault('appenlight.extra', {})
48 environ.setdefault('appenlight.extra', {})
50 environ['appenlight.extra'][section] = value
49 environ['appenlight.extra'][section] = value
51
50
52
51
53 def wrap_in_appenlight_if_enabled(app, config, appenlight_client=None):
52 def wrap_in_appenlight_if_enabled(app, settings, appenlight_client=None):
54 """
53 """
55 Wraps the given `app` for appenlight support.
54 Wraps the given `app` for appenlight support.
56
55
57 .. important::
56 .. important::
58
57
59 Appenlight expects that the wrapper is executed only once, that's why
58 Appenlight expects that the wrapper is executed only once, that's why
60 the parameter `appenlight_client` can be used to pass in an already
59 the parameter `appenlight_client` can be used to pass in an already
61 existing client instance to avoid that decorators are applied more than
60 existing client instance to avoid that decorators are applied more than
62 once.
61 once.
63
62
64 This is in use to support our setup of the vcs related middlewares.
63 This is in use to support our setup of the vcs related middlewares.
65
64
66 """
65 """
67 if asbool(config['app_conf'].get('appenlight')):
66 if settings['appenlight']:
68 app = RemoteTracebackTracker(app)
67 app = RemoteTracebackTracker(app)
69 if not appenlight_client:
68 if not appenlight_client:
70 app = make_appenlight_middleware(app, config)
69 app = make_appenlight_middleware(app, settings)
71 appenlight_client = app.appenlight_client
70 appenlight_client = app.appenlight_client
72 else:
71 else:
73 app = AppenlightWSGIWrapper(app, appenlight_client)
72 app = AppenlightWSGIWrapper(app, appenlight_client)
74 return app, appenlight_client
73 return app, appenlight_client
75
74
76
75
77 class RemoteTracebackTracker(object):
76 class RemoteTracebackTracker(object):
78 """
77 """
79 Utility middleware which forwards Pyro4 remote traceback information.
78 Utility middleware which forwards Pyro4 remote traceback information.
80 """
79 """
81
80
82 def __init__(self, app):
81 def __init__(self, app):
83 self.application = app
82 self.application = app
84
83
85 def __call__(self, environ, start_response):
84 def __call__(self, environ, start_response):
86 try:
85 try:
87 return self.application(environ, start_response)
86 return self.application(environ, start_response)
88 except Exception as e:
87 except Exception as e:
89 if hasattr(e, '_pyroTraceback'):
88 if hasattr(e, '_pyroTraceback'):
90 track_extra_information(
89 track_extra_information(
91 environ, 'remote_traceback', ''.join(e._pyroTraceback))
90 environ, 'remote_traceback', ''.join(e._pyroTraceback))
92 raise
91 raise
General Comments 0
You need to be logged in to leave comments. Login now