@@ -367,15 +367,36 @@ def initialize_telemetry_client(
367367 """Initialize a telemetry client for a specific connection if telemetry is enabled"""
368368 try :
369369
370+ print (
371+ "\n WAITING: Initializing telemetry client: %s" ,
372+ session_id_hex ,
373+ flush = True ,
374+ )
370375 with TelemetryClientFactory ._lock :
376+ print (
377+ "\n ACQUIRED: Initializing telemetry client, got lock: %s" ,
378+ session_id_hex ,
379+ flush = True ,
380+ )
371381 TelemetryClientFactory ._initialize ()
382+ print (
383+ "\n TelemetryClientFactory initialized: %s" ,
384+ session_id_hex ,
385+ flush = True ,
386+ )
372387
373388 if session_id_hex not in TelemetryClientFactory ._clients :
389+ print (
390+ "\n Session ID not in clients: %s" ,
391+ session_id_hex ,
392+ flush = True ,
393+ )
374394 logger .debug (
375395 "Creating new TelemetryClient for connection %s" ,
376396 session_id_hex ,
377397 )
378398 if telemetry_enabled :
399+ print ("\n Telemetry enabled: %s" , session_id_hex , flush = True )
379400 TelemetryClientFactory ._clients [
380401 session_id_hex
381402 ] = TelemetryClient (
@@ -385,11 +406,41 @@ def initialize_telemetry_client(
385406 host_url = host_url ,
386407 executor = TelemetryClientFactory ._executor ,
387408 )
409+ print (
410+ "\n Telemetry client initialized: %s" ,
411+ session_id_hex ,
412+ flush = True ,
413+ )
388414 else :
415+ print (
416+ "\n Telemetry disabled: %s" , session_id_hex , flush = True
417+ )
389418 TelemetryClientFactory ._clients [
390419 session_id_hex
391420 ] = NoopTelemetryClient ()
421+ print (
422+ "\n Noop Telemetry client initialized: %s" ,
423+ session_id_hex ,
424+ flush = True ,
425+ )
426+ else :
427+ print (
428+ "\n Session ID already in clients: %s" ,
429+ session_id_hex ,
430+ flush = True ,
431+ )
432+ print (
433+ "\n RELEASED: Telemetry client initialized: %s" ,
434+ session_id_hex ,
435+ flush = True ,
436+ )
392437 except Exception as e :
438+ print (
439+ "\n ERROR: Failed to initialize telemetry client: %s due to %s" ,
440+ session_id_hex ,
441+ e ,
442+ flush = True ,
443+ )
393444 logger .debug ("Failed to initialize telemetry client: %s" , e )
394445 # Fallback to NoopTelemetryClient to ensure connection doesn't fail
395446 TelemetryClientFactory ._clients [session_id_hex ] = NoopTelemetryClient ()
@@ -413,8 +464,13 @@ def get_telemetry_client(session_id_hex):
413464 @staticmethod
414465 def close (session_id_hex ):
415466 """Close and remove the telemetry client for a specific connection"""
416-
467+ print ( " \n WAITING: Closing telemetry client: %s" , session_id_hex , flush = True )
417468 with TelemetryClientFactory ._lock :
469+ print (
470+ "\n ACQUIRED: Closing telemetry client, got lock: %s" ,
471+ session_id_hex ,
472+ flush = True ,
473+ )
418474 # if (
419475 # telemetry_client := TelemetryClientFactory._clients.pop(
420476 # session_id_hex, None
@@ -432,6 +488,16 @@ def close(session_id_hex):
432488 logger .debug (
433489 "No more telemetry clients, shutting down thread pool executor"
434490 )
491+ print (
492+ "\n SHUTDOWN: Shutting down thread pool executor: %s" ,
493+ session_id_hex ,
494+ flush = True ,
495+ )
435496 TelemetryClientFactory ._executor .shutdown (wait = True )
436497 TelemetryClientFactory ._executor = None
437498 TelemetryClientFactory ._initialized = False
499+ print (
500+ "\n RELEASED: Thread pool executor shut down: %s" ,
501+ session_id_hex ,
502+ flush = True ,
503+ )
0 commit comments