@@ -190,6 +190,7 @@ def __init__(
190190 self ._session_id_hex = session_id_hex
191191 self ._auth_provider = auth_provider
192192 self ._user_agent = None
193+ self ._lock = threading .RLock ()
193194 self ._pending_futures = set ()
194195
195196 # OPTIMIZATION: Use lock-free Queue instead of list + lock
@@ -443,9 +444,9 @@ class TelemetryClientFactory:
443444 It uses a thread pool to handle asynchronous operations and a single flush thread for all clients.
444445 """
445446
446- _clients : Dict [str , BaseTelemetryClient ] = (
447- {}
448- ) # Map of session_id_hex -> BaseTelemetryClient
447+ _clients : Dict [
448+ str , BaseTelemetryClient
449+ ] = {} # Map of session_id_hex -> BaseTelemetryClient
449450 _executor : Optional [ThreadPoolExecutor ] = None
450451 _initialized : bool = False
451452 _lock = threading .RLock () # Thread safety for factory operations
@@ -546,8 +547,9 @@ def initialize_telemetry_client(
546547 session_id_hex ,
547548 )
548549 if telemetry_enabled :
549- TelemetryClientFactory ._clients [session_id_hex ] = (
550- TelemetryClient (
550+ TelemetryClientFactory ._clients [
551+ session_id_hex
552+ ] = TelemetryClient (
551553 telemetry_enabled = telemetry_enabled ,
552554 session_id_hex = session_id_hex ,
553555 auth_provider = auth_provider ,
@@ -556,11 +558,10 @@ def initialize_telemetry_client(
556558 batch_size = batch_size ,
557559 client_context = client_context ,
558560 )
559- )
560561 else :
561- TelemetryClientFactory ._clients [session_id_hex ] = (
562- NoopTelemetryClient ()
563- )
562+ TelemetryClientFactory ._clients [
563+ session_id_hex
564+ ] = NoopTelemetryClient ( )
564565 except Exception as e :
565566 logger .debug ("Failed to initialize telemetry client: %s" , e )
566567 # Fallback to NoopTelemetryClient to ensure connection doesn't fail
0 commit comments