@@ -367,15 +367,36 @@ def initialize_telemetry_client(
367
367
"""Initialize a telemetry client for a specific connection if telemetry is enabled"""
368
368
try :
369
369
370
+ print (
371
+ "\n WAITING: Initializing telemetry client: %s" ,
372
+ session_id_hex ,
373
+ flush = True ,
374
+ )
370
375
with TelemetryClientFactory ._lock :
376
+ print (
377
+ "\n ACQUIRED: Initializing telemetry client, got lock: %s" ,
378
+ session_id_hex ,
379
+ flush = True ,
380
+ )
371
381
TelemetryClientFactory ._initialize ()
382
+ print (
383
+ "\n TelemetryClientFactory initialized: %s" ,
384
+ session_id_hex ,
385
+ flush = True ,
386
+ )
372
387
373
388
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
+ )
374
394
logger .debug (
375
395
"Creating new TelemetryClient for connection %s" ,
376
396
session_id_hex ,
377
397
)
378
398
if telemetry_enabled :
399
+ print ("\n Telemetry enabled: %s" , session_id_hex , flush = True )
379
400
TelemetryClientFactory ._clients [
380
401
session_id_hex
381
402
] = TelemetryClient (
@@ -385,11 +406,41 @@ def initialize_telemetry_client(
385
406
host_url = host_url ,
386
407
executor = TelemetryClientFactory ._executor ,
387
408
)
409
+ print (
410
+ "\n Telemetry client initialized: %s" ,
411
+ session_id_hex ,
412
+ flush = True ,
413
+ )
388
414
else :
415
+ print (
416
+ "\n Telemetry disabled: %s" , session_id_hex , flush = True
417
+ )
389
418
TelemetryClientFactory ._clients [
390
419
session_id_hex
391
420
] = 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
+ )
392
437
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
+ )
393
444
logger .debug ("Failed to initialize telemetry client: %s" , e )
394
445
# Fallback to NoopTelemetryClient to ensure connection doesn't fail
395
446
TelemetryClientFactory ._clients [session_id_hex ] = NoopTelemetryClient ()
@@ -413,8 +464,13 @@ def get_telemetry_client(session_id_hex):
413
464
@staticmethod
414
465
def close (session_id_hex ):
415
466
"""Close and remove the telemetry client for a specific connection"""
416
-
467
+ print ( " \n WAITING: Closing telemetry client: %s" , session_id_hex , flush = True )
417
468
with TelemetryClientFactory ._lock :
469
+ print (
470
+ "\n ACQUIRED: Closing telemetry client, got lock: %s" ,
471
+ session_id_hex ,
472
+ flush = True ,
473
+ )
418
474
# if (
419
475
# telemetry_client := TelemetryClientFactory._clients.pop(
420
476
# session_id_hex, None
@@ -432,6 +488,16 @@ def close(session_id_hex):
432
488
logger .debug (
433
489
"No more telemetry clients, shutting down thread pool executor"
434
490
)
491
+ print (
492
+ "\n SHUTDOWN: Shutting down thread pool executor: %s" ,
493
+ session_id_hex ,
494
+ flush = True ,
495
+ )
435
496
TelemetryClientFactory ._executor .shutdown (wait = True )
436
497
TelemetryClientFactory ._executor = None
437
498
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