# HG changeset patch # User RhodeCode Admin # Date 2023-02-02 20:21:36 # Node ID 63ff36b5b6dcf188200b65c74e6a544ea3573fe8 # Parent e536cb7df7844d8893373bf996521019e798a68c request-tracker: expose more info about repo-name/method in tracking calls diff --git a/vcsserver/tweens/request_wrapper.py b/vcsserver/tweens/request_wrapper.py --- a/vcsserver/tweens/request_wrapper.py +++ b/vcsserver/tweens/request_wrapper.py @@ -34,6 +34,14 @@ def get_user_agent(environ): return environ.get('HTTP_USER_AGENT') +def get_vcs_method(environ): + return environ.get('HTTP_X_RC_METHOD') + + +def get_vcs_repo(environ): + return environ.get('HTTP_X_RC_REPO_NAME') + + class RequestWrapperTween(object): def __init__(self, handler, registry): self.handler = handler @@ -45,6 +53,11 @@ class RequestWrapperTween(object): start = time.time() log.debug('Starting request time measurement') response = None + + ua = get_user_agent(request.environ) + vcs_method = get_vcs_method(request.environ) + repo_name = get_vcs_repo(request.environ) + try: response = self.handler(request) finally: @@ -56,12 +69,15 @@ class RequestWrapperTween(object): resp_code = getattr(response, 'status_code', 'UNDEFINED') total = time.time() - start + + _view_path = "{}/{}@{}".format(_path, vcs_method, repo_name) log.info( 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], VCSServer %s', count, ip, request.environ.get('REQUEST_METHOD'), - _path, total, get_user_agent(request.environ), _ver_, + _view_path, total, ua, _ver_, extra={"time": total, "ver": _ver_, "code": resp_code, - "path": _path, "view_name": match_route} + "path": _path, "view_name": match_route, "user_agent": ua, + "vcs_method": vcs_method, "repo_name": repo_name} ) statsd = request.registry.statsd @@ -81,6 +97,7 @@ class RequestWrapperTween(object): "view_name:{}".format(match_route), "code:{}".format(resp_code) ]) + return response