From e305dad557dc993073fac84d568e5e7689f56d04 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Sat, 28 Jun 2014 22:09:26 +0400 Subject: [PATCH] Add profiling support to glanceclinet To be able to create profiling traces for Glance, client should be able to send special HTTP header that contains trace info. This patch is as well important to be able to make cross project traces. (Typical case nova calls glance via python client, if profiler is initialized in nova, glance client will add extra header, that will be parsed by special osprofiler middleware in glance api) Don't worry no security issue here, trace information is signed by HMAC key that is setted in api-paste.ini. So only person that knows HMAC key is able to send proper header. Change-Id: Ib13084fbe9b33c2f3dee165f7d6c778546cce6ca --- glanceclient/common/http.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index d1dc61de..6cff1cc0 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -39,9 +39,12 @@ import OpenSSL from glanceclient.common import utils from glanceclient import exc +from glanceclient.openstack.common import importutils from glanceclient.openstack.common import network_utils from glanceclient.openstack.common import strutils +osprofiler_web = importutils.try_import("osprofiler.web") + try: from eventlet import patcher # Handle case where we are running in a monkey patched environment @@ -175,6 +178,10 @@ class HTTPClient(object): # Copy the kwargs so we can reuse the original in case of redirects kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {})) kwargs['headers'].setdefault('User-Agent', USER_AGENT) + + if osprofiler_web: + kwargs['headers'].update(osprofiler_web.get_trace_id_headers()) + if self.auth_token: kwargs['headers'].setdefault('X-Auth-Token', self.auth_token)