@@ -103,6 +103,7 @@ def can_send(self):
103103 @return: Boolean
104104 """
105105 # Watch for pid change (fork)
106+ self .last_fork_check = datetime .now ()
106107 current_pid = os .getpid ()
107108 if self ._boot_pid != current_pid :
108109 self ._boot_pid = current_pid
@@ -280,6 +281,51 @@ def handle_agent_tasks(self, task):
280281
281282 self .__task_response (task ["messageId" ], payload )
282283
284+
285+ def diagnostics (self ):
286+ """
287+ Helper function to dump out state.
288+ """
289+ try :
290+ import threading
291+ dt_format = "%Y-%m-%d %H:%M:%S"
292+
293+ logger .warning ("====> Instana Python Language Agent Diagnostics <====" )
294+
295+ logger .warning ("----> Agent <----" )
296+ logger .warning ("is_agent_ready: %s" , self .is_agent_ready ())
297+ logger .warning ("is_timed_out: %s" , self .is_timed_out ())
298+ if self .last_seen is None :
299+ logger .warning ("last_seen: None" )
300+ else :
301+ logger .warning ("last_seen: %s" , self .last_seen .strftime (dt_format ))
302+
303+ if self .announce_data is not None :
304+ logger .warning ("announce_data: %s" , self .announce_data .__dict__ )
305+ else :
306+ logger .warning ("announce_data: None" )
307+
308+ logger .warning ("Options: %s" , self .options .__dict__ )
309+
310+ logger .warning ("----> StateMachine <----" )
311+ logger .warning ("State: %s" , self .machine .fsm .current )
312+
313+ logger .warning ("----> Collector <----" )
314+ logger .warning ("Collector: %s" , self .collector )
315+ logger .warning ("is_collector_thread_running?: %s" , self .collector .is_reporting_thread_running ())
316+ logger .warning ("background_report_lock.locked?: %s" , self .collector .background_report_lock .locked ())
317+ logger .warning ("ready_to_start: %s" , self .collector .ready_to_start )
318+ logger .warning ("reporting_thread: %s" , self .collector .reporting_thread )
319+ logger .warning ("report_interval: %s" , self .collector .report_interval )
320+ logger .warning ("should_send_snapshot_data: %s" , self .collector .should_send_snapshot_data ())
321+ logger .warning ("spans in queue: %s" , self .collector .span_queue .qsize ())
322+ logger .warning ("thread_shutdown is_set: %s" , self .collector .thread_shutdown .is_set ())
323+
324+ logger .warning ("----> Threads <----" )
325+ logger .warning ("Threads: %s" , threading .enumerate ())
326+ except Exception :
327+ logger .warning ("Non-fatal diagnostics exception: " , exc_info = True )
328+
283329 def __task_response (self , message_id , data ):
284330 """
285331 When the host agent passes us a task and we do it, this function is used to
0 commit comments