##// END OF EJS Templates
debug: add new custom logging to track unique requests across systems.
marcink -
r2794:9b8d6c69 default
parent child Browse files
Show More
@@ -0,0 +1,29 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2017-2018 RhodeCode GmbH
4 #
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
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 from uuid import uuid4
22 from pyramid.decorator import reify
23 from pyramid.request import Request as _Request
24
25
26 class Request(_Request):
27 @reify
28 def req_id(self):
29 return str(uuid4())
@@ -38,6 +38,7 b' from rhodecode.config import utils as co'
38 from rhodecode.config.environment import load_pyramid_environment
38 from rhodecode.config.environment import load_pyramid_environment
39
39
40 from rhodecode.lib.middleware.vcs import VCSMiddleware
40 from rhodecode.lib.middleware.vcs import VCSMiddleware
41 from rhodecode.lib.request import Request
41 from rhodecode.lib.vcs import VCSCommunicationError
42 from rhodecode.lib.vcs import VCSCommunicationError
42 from rhodecode.lib.exceptions import VCSServerUnavailable
43 from rhodecode.lib.exceptions import VCSServerUnavailable
43 from rhodecode.lib.middleware.appenlight import wrap_in_appenlight_if_enabled
44 from rhodecode.lib.middleware.appenlight import wrap_in_appenlight_if_enabled
@@ -192,6 +193,7 b' def includeme_first(config):'
192
193
193 def includeme(config):
194 def includeme(config):
194 settings = config.registry.settings
195 settings = config.registry.settings
196 config.set_request_factory(Request)
195
197
196 # plugin information
198 # plugin information
197 config.registry.rhodecode_plugins = collections.OrderedDict()
199 config.registry.rhodecode_plugins = collections.OrderedDict()
@@ -123,6 +123,35 b' class ColorFormatter(ExceptionAwareForma'
123 return colored_record
123 return colored_record
124
124
125
125
126 def _inject_req_id(record):
127 from pyramid.threadlocal import get_current_request
128 req = get_current_request()
129 req_id = 'req_id:%-36s ' % (getattr(req, 'req_id', None))
130 record.req_id = req_id
131
132
133 class RequestTrackingFormatter(ExceptionAwareFormatter):
134 def format(self, record):
135 _inject_req_id(record)
136 def_record = logging.Formatter.format(self, record)
137 return def_record
138
139
140 class ColorRequestTrackingFormatter(ColorFormatter):
141 def format(self, record):
142 """
143 Changes record's levelname to use with COLORS enum
144 """
145 _inject_req_id(record)
146 levelname = record.levelname
147 start = COLOR_SEQ % (COLORS[levelname])
148 def_record = logging.Formatter.format(self, record)
149 end = RESET_SEQ
150
151 colored_record = ''.join([start, def_record, end])
152 return colored_record
153
154
126 class ColorFormatterSql(logging.Formatter):
155 class ColorFormatterSql(logging.Formatter):
127
156
128 def format(self, record):
157 def format(self, record):
@@ -158,7 +158,7 b' def detect_vcs_request(environ, backends'
158 log.debug('got handler:%s from environ', handler)
158 log.debug('got handler:%s from environ', handler)
159
159
160 if not handler:
160 if not handler:
161 log.debug('checking if request is of VCS type in order: %s', backends)
161 log.debug('request start: checking if request is of VCS type in order: %s', backends)
162 for vcs_type in backends:
162 for vcs_type in backends:
163 vcs_check, _handler = checks[vcs_type]
163 vcs_check, _handler = checks[vcs_type]
164 if vcs_check(environ):
164 if vcs_check(environ):
@@ -21,9 +21,10 b''
21 import os
21 import os
22 from pyramid.compat import configparser
22 from pyramid.compat import configparser
23 from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # noqa
23 from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # noqa
24 from pyramid.request import Request
25 from pyramid.scripting import prepare
24 from pyramid.scripting import prepare
26
25
26 from rhodecode.lib.request import Request
27
27
28
28 def get_config(ini_path, **kwargs):
29 def get_config(ini_path, **kwargs):
29 parser = configparser.ConfigParser(**kwargs)
30 parser = configparser.ConfigParser(**kwargs)
@@ -41,7 +41,7 b' import pkg_resources'
41 from webhelpers.text import collapse, remove_formatting, strip_tags
41 from webhelpers.text import collapse, remove_formatting, strip_tags
42 from mako import exceptions
42 from mako import exceptions
43 from pyramid.threadlocal import get_current_registry
43 from pyramid.threadlocal import get_current_registry
44 from pyramid.request import Request
44 from rhodecode.lib.request import Request
45
45
46 from rhodecode.lib.fakemod import create_module
46 from rhodecode.lib.fakemod import create_module
47 from rhodecode.lib.vcs.backends.base import Config
47 from rhodecode.lib.vcs.backends.base import Config
@@ -86,6 +86,8 b' def add_request_user_context(event):'
86 Adds auth user into request context
86 Adds auth user into request context
87 """
87 """
88 request = event.request
88 request = event.request
89 # access req_id as soon as possible
90 req_id = request.req_id
89
91
90 if hasattr(request, 'vcs_call'):
92 if hasattr(request, 'vcs_call'):
91 # skip vcs calls
93 # skip vcs calls
@@ -98,7 +100,7 b' def add_request_user_context(event):'
98 auth_user = get_auth_user(request)
100 auth_user = get_auth_user(request)
99 request.user = auth_user
101 request.user = auth_user
100 request.environ['rc_auth_user'] = auth_user
102 request.environ['rc_auth_user'] = auth_user
101
103 request.environ['rc_req_id'] = req_id
102
104
103 def inject_app_settings(event):
105 def inject_app_settings(event):
104 settings = event.app.registry.settings
106 settings = event.app.registry.settings
General Comments 0
You need to be logged in to leave comments. Login now