@@ -110,6 +110,7 @@ def __init__(
110110 self .unleash_app_name = app_name
111111 self .unleash_environment = environment
112112 self .unleash_instance_id = instance_id
113+ self ._connection_id = str (uuid .uuid4 ())
113114 self .unleash_refresh_interval = refresh_interval
114115 self .unleash_request_timeout = request_timeout
115116 self .unleash_request_retries = request_retries
@@ -183,6 +184,18 @@ def __init__(
183184 engine = self .engine ,
184185 )
185186
187+ @property
188+ def unleash_refresh_interval_str_millis (self ) -> str :
189+ return str (self .unleash_refresh_interval * 1000 )
190+
191+ @property
192+ def unleash_metrics_interval_str_millis (self ) -> str :
193+ return str (self .unleash_metrics_interval * 1000 )
194+
195+ @property
196+ def connection_id (self ):
197+ return self ._connection_id
198+
186199 def initialize_client (self , fetch_toggles : bool = True ) -> None :
187200 """
188201 Initializes client and starts communication with central unleash server(s).
@@ -213,19 +226,25 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
213226 if not self .is_initialized :
214227 # pylint: disable=no-else-raise
215228 try :
216- headers = {
229+ base_headers = {
217230 ** self .unleash_custom_headers ,
218- "unleash-connection-id" : str ( uuid . uuid4 ()) ,
231+ "unleash-connection-id" : self . connection_id ,
219232 "unleash-appname" : self .unleash_app_name ,
220233 "unleash-sdk" : f"{ SDK_NAME } :{ SDK_VERSION } " ,
221234 }
222235
236+ metrics_headers = {
237+ ** base_headers ,
238+ "unleash-interval" : self .unleash_metrics_interval_str_millis ,
239+ }
240+
223241 # Setup
224242 metrics_args = {
225243 "url" : self .unleash_url ,
226244 "app_name" : self .unleash_app_name ,
245+ "connection_id" : self .connection_id ,
227246 "instance_id" : self .unleash_instance_id ,
228- "headers" : headers ,
247+ "headers" : metrics_headers ,
229248 "custom_options" : self .unleash_custom_options ,
230249 "request_timeout" : self .unleash_request_timeout ,
231250 "engine" : self .engine ,
@@ -237,19 +256,25 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
237256 self .unleash_url ,
238257 self .unleash_app_name ,
239258 self .unleash_instance_id ,
259+ self .connection_id ,
240260 self .unleash_metrics_interval ,
241- headers ,
261+ base_headers ,
242262 self .unleash_custom_options ,
243263 self .strategy_mapping ,
244264 self .unleash_request_timeout ,
245265 )
246266
247267 if fetch_toggles :
268+ fetch_headers = {
269+ ** base_headers ,
270+ "unleash-interval" : self .unleash_refresh_interval_str_millis ,
271+ }
272+
248273 job_args = {
249274 "url" : self .unleash_url ,
250275 "app_name" : self .unleash_app_name ,
251276 "instance_id" : self .unleash_instance_id ,
252- "headers" : headers ,
277+ "headers" : fetch_headers ,
253278 "custom_options" : self .unleash_custom_options ,
254279 "cache" : self .cache ,
255280 "engine" : self .engine ,
@@ -277,7 +302,6 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
277302 executor = self .unleash_executor_name ,
278303 kwargs = job_args ,
279304 )
280-
281305 if not self .unleash_disable_metrics :
282306 self .metric_job = self .unleash_scheduler .add_job (
283307 aggregate_and_send_metrics ,
0 commit comments