Log request-id for each api call

This patch adds support to log 'X-Openstack-Request-Id' for each api call.

Change-Id: Ia17d6c4cc021246316a7317011596e0e2efa37be
Closes-Bug: #1604306
This commit is contained in:
Hirofumi Ichihara 2016-07-19 18:18:49 +09:00
parent 6bc4685f6b
commit 53e2ad1ba9
3 changed files with 19 additions and 1 deletions

View File

@ -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):

View File

@ -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

View File

@ -0,0 +1,3 @@
---
features:
- Added support to log 'x-openstack-request-id' for each api call.