From 96151efd518021f0e56e6518a1326e6d0ac91981 Mon Sep 17 00:00:00 2001 From: Abhishek Kekane Date: Tue, 17 May 2016 11:23:28 +0000 Subject: [PATCH] Log request-id for each api call Added support to log 'X-Openstack-Request-Id' for each api call. If glanceclient is used from command line then following log will be logged on console if --debug flag is used. DEBUG:glanceclient.common.http:GET call to glance-api for http://172.26.88.20:9292/v2/schemas/image used request id req-e0c7c97a-8fc0-4ce3-a669-d0b1eb5d7aae If python-glanceclient is used in applications (e.g. Nova) then following log message will be logged in service logs. DEBUG glanceclient.common.http [req-be074f1e-1c17-4786-b703-2a221751c8f4 demo demo] GET call to glance-api for http://172.26.88.20:9292/v1/images/detail?is_public=none&limit=20 used request id req-9b1dd929-df30-46b2-a8f2-dfd6ffbad3fc DocImpact: To use this feature user need to set 'default_log_levels' in third party application. For example nova uses glance then in nova.conf 'default_log_levels' should be set as below: default_log_levels = glanceclient=DEBUG Implements: blueprint log-request-id Change-Id: Ib04a07bac41ad2a5e997348f3b0bccc640169dc9 --- glanceclient/common/http.py | 10 ++++++++++ .../notes/log-request-id-e7f67a23a0ed5c7b.yaml | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 releasenotes/notes/log-request-id-e7f67a23a0ed5c7b.yaml diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index 1bec45c..0eb42de 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -120,6 +120,16 @@ class _BaseHTTPClient(object): except ValueError: body_iter = None + # log request-id for each api call + request_id = resp.headers.get('x-openstack-request-id') + if request_id: + LOG.debug('%(method)s call to glance-api for ' + '%(url)s used request id ' + '%(response_request_id)s', + {'method': resp.request.method, + 'url': resp.url, + 'response_request_id': request_id}) + return resp, body_iter diff --git a/releasenotes/notes/log-request-id-e7f67a23a0ed5c7b.yaml b/releasenotes/notes/log-request-id-e7f67a23a0ed5c7b.yaml new file mode 100644 index 0000000..452246f --- /dev/null +++ b/releasenotes/notes/log-request-id-e7f67a23a0ed5c7b.yaml @@ -0,0 +1,6 @@ +--- +features: + - Added support to log 'x-openstack-request-id' for each api call. + Please refer, + https://blueprints.launchpad.net/python-glanceclient/+spec/log-request-id + for more details.