@@ -205,8 +205,8 @@ class _CmapTelemetry:
205205 "_client_id" ,
206206 "_conn_created_start" ,
207207 "_listeners" ,
208- "_should_log " ,
209- "_should_publish " ,
208+ "_log " ,
209+ "_publish " ,
210210 )
211211
212212 def __init__ (
@@ -220,11 +220,19 @@ def __init__(
220220 self ._client_id = client_id
221221 self ._address = address
222222 self ._listeners = listeners
223- self ._should_publish = publish and listeners is not None and listeners .enabled_for_cmap
224- self ._should_log = log
223+ self ._publish = publish
224+ self ._log = log
225+
226+ @property
227+ def _should_publish (self ) -> bool :
228+ return self ._publish and self ._listeners is not None and self ._listeners .enabled_for_cmap
229+
230+ @property
231+ def _should_log (self ) -> bool :
232+ return self ._log and _CONNECTION_LOGGER .isEnabledFor (logging .DEBUG )
225233
226234 def _emit_log (self , message : _ConnectionStatusMessage , ** extra : Any ) -> None :
227- if self ._should_log and _CONNECTION_LOGGER . isEnabledFor ( logging . DEBUG ) :
235+ if self ._should_log :
228236 _debug_log (
229237 _CONNECTION_LOGGER ,
230238 message = message ,
@@ -359,8 +367,16 @@ def __init__(
359367 self ._publish = publish
360368 self ._awaited = awaited
361369
370+ @property
371+ def _should_publish (self ) -> bool :
372+ return self ._publish and self ._listeners is not None
373+
374+ @property
375+ def _should_log (self ) -> bool :
376+ return _SDAM_LOGGER .isEnabledFor (logging .DEBUG )
377+
362378 def _emit_log (self , message : _SDAMStatusMessage , ** extra : Any ) -> None :
363- if _SDAM_LOGGER . isEnabledFor ( logging . DEBUG ) :
379+ if self . _should_log :
364380 _debug_log (
365381 _SDAM_LOGGER ,
366382 message = message ,
@@ -374,7 +390,7 @@ def _emit_log(self, message: _SDAMStatusMessage, **extra: Any) -> None:
374390 def started (self ) -> None :
375391 """Publish the APM heartbeat-started event (before connection checkout)."""
376392 self ._start = time .monotonic ()
377- if self ._publish :
393+ if self ._should_publish :
378394 assert self ._listeners is not None
379395 self ._listeners .publish_server_heartbeat_started (self ._address , self ._awaited )
380396
@@ -394,7 +410,7 @@ def succeeded(
394410 server_conn_id : Optional [int ],
395411 ) -> None :
396412 """Emit the SUCCEEDED log entry and APM event."""
397- if self ._publish :
413+ if self ._should_publish :
398414 assert self ._listeners is not None
399415 self ._listeners .publish_server_heartbeat_succeeded (
400416 self ._address , round_trip_time , response , response .awaitable
@@ -410,7 +426,7 @@ def succeeded(
410426 def failed (self , error : Exception , conn_id : Optional [int ]) -> None :
411427 """Emit the FAILED log entry and APM event."""
412428 duration = max (0.0 , time .monotonic () - self ._start )
413- if self ._publish :
429+ if self ._should_publish :
414430 assert self ._listeners is not None
415431 self ._listeners .publish_server_heartbeat_failed (
416432 self ._address , duration , error , self ._awaited
@@ -429,7 +445,7 @@ class _SdamTelemetry:
429445 Topology events are queued for asynchronous delivery; log entries are emitted inline.
430446 """
431447
432- __slots__ = ("_events" , "_listeners" , "_publish_server" , "_publish_tp" , " _topology_id" )
448+ __slots__ = ("_events" , "_listeners" , "_topology_id" )
433449
434450 def __init__ (
435451 self ,
@@ -440,15 +456,25 @@ def __init__(
440456 self ._topology_id = topology_id
441457 self ._listeners = listeners
442458 self ._events = events
443- self ._publish_server = listeners is not None and listeners .enabled_for_server
444- self ._publish_tp = listeners is not None and listeners .enabled_for_topology
459+
460+ @property
461+ def _publish_server (self ) -> bool :
462+ return self ._listeners is not None and self ._listeners .enabled_for_server
463+
464+ @property
465+ def _publish_tp (self ) -> bool :
466+ return self ._listeners is not None and self ._listeners .enabled_for_topology
467+
468+ @property
469+ def _should_log (self ) -> bool :
470+ return _SDAM_LOGGER .isEnabledFor (logging .DEBUG )
445471
446472 def _enqueue (self , fn : Any , args : tuple [Any , ...]) -> None :
447473 if self ._events is not None :
448474 self ._events .put ((fn , args ))
449475
450476 def _emit_log (self , message : _SDAMStatusMessage , ** extra : Any ) -> None :
451- if _SDAM_LOGGER . isEnabledFor ( logging . DEBUG ) :
477+ if self . _should_log :
452478 _debug_log (
453479 _SDAM_LOGGER ,
454480 message = message ,
0 commit comments