Skip to content

Commit

Permalink
Merge pull request #256 from shakenfist/expose-request-id
Browse files Browse the repository at this point in the history
Better expose request ids.
  • Loading branch information
mikalstill authored Jan 30, 2024
2 parents 8673ce3 + 0954e01 commit 5cf1e17
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions shakenfist_client/apiclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __init__(self, base_url=None, verbose=False,
if logger:
LOG = logger

self.most_recent_request_id = None
self.sync_request_timeout = sync_request_timeout

LOG.debug('Client initially configured with apiurl of %s for namespace %s '
Expand Down Expand Up @@ -192,8 +193,10 @@ def _actual_request_url(self, method, url, data=None,
allow_redirects=True, stream=False):
url = self.base_url + url

h = {'Authorization': self.cached_auth,
'User-Agent': get_user_agent()}
h = {
'Authorization': self.cached_auth,
'User-Agent': get_user_agent()
}
if data:
if request_body_is_binary:
h['Content-Type'] = 'application/octet-stream'
Expand All @@ -208,6 +211,11 @@ def _actual_request_url(self, method, url, data=None,

LOG.debug('-------------------------------------------------------')
LOG.debug('API client requested: %s %s' % (method, url))
for hkey in h:
if hkey == 'Authorization' and h[hkey]:
LOG.debug('Header: Authorization = Bearer *****')
else:
LOG.debug('Header: %s = %s' % (hkey, h[hkey]))
if data:
if request_body_is_binary:
LOG.debug('Data: ...%d bytes of binary omitted...' % len(data))
Expand All @@ -219,6 +227,10 @@ def _actual_request_url(self, method, url, data=None,
LOG.debug('API client response: code = %s (took %.02f seconds)'
% (r.status_code, (end_time - start_time)))

self.most_recent_request_id = r.headers['X-Request-ID']
for hkey in r.headers:
LOG.debug('Header: %s = %s' % (hkey, r.headers[hkey]))

if not stream and r.text:
if response_body_is_binary:
LOG.debug('Data: ...%d bytes of binary omitted...'
Expand Down

0 comments on commit 5cf1e17

Please sign in to comment.