11"""Encapsulate common rest operations between business services propagating trace headers if configured.
22"""
3+ import logging
4+
35import opentracing
46import requests
5- from flask import current_app
7+ from flask import current_app , request
68
9+ from pyms .constants import LOGGER_NAME
710from pyms .flask .services .driver import DriverService
811
12+ logger = logging .getLogger (LOGGER_NAME )
13+
914
1015class Service (DriverService ):
1116 service = "requests"
@@ -27,10 +32,10 @@ def insert_trace_headers(self, headers):
2732
2833 try :
2934 # FLASK https://github.com/opentracing-contrib/python-flask
30- span = self ._tracer .get_span ()
31- self ._tracer ._tracer .inject (span , opentracing .Format .HTTP_HEADERS , headers )
35+ span = self ._tracer .get_span (request )
36+ self ._tracer .tracer .inject (span . context , opentracing .Format .HTTP_HEADERS , headers )
3237 except Exception as ex :
33- current_app . logger .warning ("Tracer error {}" .format (ex ))
38+ logger .debug ("Tracer error {}" .format (ex ))
3439 return headers
3540
3641 def _get_headers (self , headers ):
@@ -87,7 +92,7 @@ def get(self, url, path_params=None, params=None, headers=None, **kwargs):
8792 :param params: (optional) Dictionary, list of tuples or bytes to send in the body of the :class:`Request` (as query
8893 string parameters)
8994 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
90- :param \*\* kwargs: Optional arguments that ``request`` takes.
95+ :param kwargs: Optional arguments that ``request`` takes.
9196 :return: :class:`Response <Response>` object
9297 :rtype: requests.Response
9398 """
@@ -109,7 +114,7 @@ def get_for_object(self, url, path_params=None, params=None, headers=None, **kwa
109114 :param params: (optional) Dictionary, list of tuples or bytes to send in the body of the :class:`Request` (as query
110115 string parameters)
111116 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
112- :param \*\* kwargs: Optional arguments that ``request`` takes.
117+ :param kwargs: Optional arguments that ``request`` takes.
113118 :return: :class:`Response <Response>` object
114119 :rtype: requests.Response
115120 """
@@ -126,7 +131,7 @@ def post(self, url, path_params=None, data=None, json=None, headers=None, **kwar
126131 :class:`Request`.
127132 :param json: (optional) json data to send in the body of the :class:`Request`.
128133 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
129- :param \*\* kwargs: Optional arguments that ``request`` takes.
134+ :param kwargs: Optional arguments that ``request`` takes.
130135 :return: :class:`Response <Response>` object
131136 :rtype: requests.Response
132137 """
@@ -149,7 +154,7 @@ def post_for_object(self, url, path_params=None, data=None, json=None, headers=N
149154 :class:`Request`.
150155 :param json: (optional) json data to send in the body of the :class:`Request`.
151156 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
152- :param \*\* kwargs: Optional arguments that ``request`` takes.
157+ :param kwargs: Optional arguments that ``request`` takes.
153158 :return: :class:`Response <Response>` object
154159 :rtype: requests.Response
155160 """
@@ -166,7 +171,7 @@ def put(self, url, path_params=None, data=None, headers=None, **kwargs):
166171 object to send in the body of the :class:`Request`.
167172 :param json: (optional) json data to send in the body of the :class:`Request`.
168173 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
169- :param \*\* kwargs: Optional arguments that ``request`` takes.
174+ :param kwargs: Optional arguments that ``request`` takes.
170175 :return: :class:`Response <Response>` object
171176 :rtype: requests.Response
172177 """
@@ -189,7 +194,7 @@ def put_for_object(self, url, path_params=None, data=None, headers=None, **kwarg
189194 object to send in the body of the :class:`Request`.
190195 :param json: (optional) json data to send in the body of the :class:`Request`.
191196 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
192- :param \*\* kwargs: Optional arguments that ``request`` takes.
197+ :param kwargs: Optional arguments that ``request`` takes.
193198 :return: :class:`Response <Response>` object
194199 :rtype: requests.Response
195200 """
@@ -203,7 +208,7 @@ def delete(self, url, path_params=None, headers=None, **kwargs):
203208 :param url: URL for the new :class:`Request` object. Could contain path parameters
204209 :param path_params: (optional) Dictionary, list of tuples with path parameters values to compose url
205210 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
206- :param \*\* kwargs: Optional arguments that ``request`` takes.
211+ :param kwargs: Optional arguments that ``request`` takes.
207212 :return: :class:`Response <Response>` object
208213 :rtype: requests.Response
209214 """
0 commit comments