@@ -19,6 +19,7 @@ def __init__(self, hostname, port, headers=None, encoder=None):
1919 self .port = port
2020 self ._traces = '/v0.3/traces'
2121 self ._services = '/v0.3/services'
22+ self ._compatibility_mode = False
2223 self ._encoder = encoder or get_encoder ()
2324
2425 # overwrite the Content-type with the one chosen in the Encoder
@@ -27,10 +28,12 @@ def __init__(self, hostname, port, headers=None, encoder=None):
2728
2829 def _downgrade (self ):
2930 """
30- Downgrades the used encoder and API level. This method must
31- fallback to a safe encoder and API, so that it will success
32- despite users' configuration
31+ Downgrades the used encoder and API level. This method must fallback to a safe
32+ encoder and API, so that it will success despite users' configurations. This action
33+ ensures that the compatibility mode is activated so that the downgrade will be
34+ executed only once.
3335 """
36+ self ._compatibility_mode = True
3437 self ._traces = '/v0.2/traces'
3538 self ._services = '/v0.2/services'
3639 self ._encoder = JSONEncoder ()
@@ -43,10 +46,9 @@ def send_traces(self, traces):
4346 data = self ._encoder .encode_traces (traces )
4447 response = self ._put (self ._traces , data )
4548
46- # the API endpoint is not available so we should
47- # downgrade the connection and re-try the call
48- if response .status == 404 :
49- log .debug ('calling the endpoint "%s" but received 404; downgrading the API' , self ._traces )
49+ # the API endpoint is not available so we should downgrade the connection and re-try the call
50+ if response .status in [404 , 415 ] and self ._compatibility_mode is False :
51+ log .debug ('calling the endpoint "%s" but received %s; downgrading the API' , self ._traces , response .status )
5052 self ._downgrade ()
5153 return self .send_traces (traces )
5254
@@ -62,9 +64,8 @@ def send_services(self, services):
6264 data = self ._encoder .encode_services (s )
6365 response = self ._put (self ._services , data )
6466
65- # the API endpoint is not available so we should
66- # downgrade the connection and re-try the call
67- if response .status == 404 :
67+ # the API endpoint is not available so we should downgrade the connection and re-try the call
68+ if response .status in [404 , 415 ] and self ._compatibility_mode is False :
6869 log .debug ('calling the endpoint "%s" but received 404; downgrading the API' , self ._services )
6970 self ._downgrade ()
7071 return self .send_services (services )
0 commit comments