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