diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py index 19bd29708..abbe8cf6d 100644 --- a/neutronclient/tests/unit/test_cli20.py +++ b/neutronclient/tests/unit/test_cli20.py @@ -66,11 +66,19 @@ class FakeStdout(object): return result +class MyRequest(requests.Request): + def __init__(self, method=None): + self.method = method + + class MyResp(requests.Response): - def __init__(self, status_code, headers=None, reason=None): + def __init__(self, status_code, headers=None, reason=None, + request=None, url=None): self.status_code = status_code self.headers = headers or {} self.reason = reason + self.request = request or MyRequest() + self.url = url class MyApp(object): diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py index 5504fd1dd..f192c061b 100644 --- a/neutronclient/v2_0/client.py +++ b/neutronclient/v2_0/client.py @@ -112,6 +112,13 @@ class _RequestIdMixin(object): # Extract 'x-openstack-request-id' from headers if # response is a Response object. request_id = resp.headers.get('x-openstack-request-id') + # log request-id for each api call + _logger.debug('%(method)s call to neutron for ' + '%(url)s used request id ' + '%(response_request_id)s', + {'method': resp.request.method, + 'url': resp.url, + 'response_request_id': request_id}) else: # If resp is of type string. request_id = resp diff --git a/releasenotes/notes/log-request-id-64bef955b8292c18.yaml b/releasenotes/notes/log-request-id-64bef955b8292c18.yaml new file mode 100644 index 000000000..62c73fa2e --- /dev/null +++ b/releasenotes/notes/log-request-id-64bef955b8292c18.yaml @@ -0,0 +1,3 @@ +--- +features: + - Added support to log 'x-openstack-request-id' for each api call. \ No newline at end of file