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:
parent
6bc4685f6b
commit
53e2ad1ba9
neutronclient
releasenotes/notes
@ -66,11 +66,19 @@ class FakeStdout(object):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class MyRequest(requests.Request):
|
||||||
|
def __init__(self, method=None):
|
||||||
|
self.method = method
|
||||||
|
|
||||||
|
|
||||||
class MyResp(requests.Response):
|
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.status_code = status_code
|
||||||
self.headers = headers or {}
|
self.headers = headers or {}
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
|
self.request = request or MyRequest()
|
||||||
|
self.url = url
|
||||||
|
|
||||||
|
|
||||||
class MyApp(object):
|
class MyApp(object):
|
||||||
|
@ -112,6 +112,13 @@ class _RequestIdMixin(object):
|
|||||||
# Extract 'x-openstack-request-id' from headers if
|
# Extract 'x-openstack-request-id' from headers if
|
||||||
# response is a Response object.
|
# response is a Response object.
|
||||||
request_id = resp.headers.get('x-openstack-request-id')
|
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:
|
else:
|
||||||
# If resp is of type string.
|
# If resp is of type string.
|
||||||
request_id = resp
|
request_id = resp
|
||||||
|
3
releasenotes/notes/log-request-id-64bef955b8292c18.yaml
Normal file
3
releasenotes/notes/log-request-id-64bef955b8292c18.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Added support to log 'x-openstack-request-id' for each api call.
|
Loading…
x
Reference in New Issue
Block a user