Skip to content

PYTHON-5846 Consolidate CMAP, heartbeat, and SDAM telemetry into _telemetry.py#15

Draft
blink1073 wants to merge 49 commits into
masterfrom
PYTHON-5846
Draft

PYTHON-5846 Consolidate CMAP, heartbeat, and SDAM telemetry into _telemetry.py#15
blink1073 wants to merge 49 commits into
masterfrom
PYTHON-5846

Conversation

@blink1073

@blink1073 blink1073 commented Jun 30, 2026

Copy link
Copy Markdown
Owner

[PYTHON-5846]

Changes in this PR

Building on PYTHON-5745, adds _CmapTelemetry, _HeartbeatTelemetry, and _SdamTelemetry classes to pymongo/_telemetry.py to consolidate the remaining APM event publishing and structured logging across pool.py, monitor.py, topology.py, and server.py.

Test Plan

  • just typing-mypy passes.
  • Pre-commit hooks pass.
  • Existing CMAP, SDAM, and heartbeat monitoring tests cover the consolidated code paths.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

blink1073 and others added 30 commits June 30, 2026 08:27
…emetry.py

Add _CmapTelemetry, _HeartbeatTelemetry, and _SdamTelemetry classes to
eliminate the repetitive if-enabled_for_cmap / if-logger.isEnabledFor
boilerplate spread across pool.py, monitor.py, topology.py, and server.py.
- Rename _CmapTelemetry._log -> _emit_log for consistency with _CommandTelemetry
- Rename _HeartbeatTelemetry.apm_started -> started to match started/succeeded/failed lifecycle
- Rename _HeartbeatTelemetry.log_started -> emit_started_log to signal it is the deferred log-only half
- Replace is_sdam flag with separate publish/log bool parameters on _CmapTelemetry
_CmapTelemetry now owns connection-creation and checkout durations:
connection_created() starts the clock, connection_ready() computes it;
checkout_started() starts the clock, checkout_succeeded/failed() compute it.

_HeartbeatTelemetry.started() starts the clock; failed() computes its
own duration instead of receiving it as a parameter.

Removes checkout_started_time from Pool._get_conn, _raise_if_not_ready,
and _raise_wait_queue_timeout, and removes AsyncConnection.creation_time.
Use response.awaitable (ground truth from wire) rather than self._awaited
(pre-computed before response) for ServerHeartbeatSucceededEvent.awaited.
Also fix stale method references in _HeartbeatTelemetry docstring.
_CmapTelemetry, _HeartbeatTelemetry, and _SdamTelemetry now compute
_should_publish and _should_log as properties that check listener state
and logger level at call time rather than caching derived booleans in
the constructor.
…y classes; document why long-lived classes use properties
…ion computation in _CmapTelemetry and _HeartbeatTelemetry
Co-authored-by: Noah Stapp <noah@noahstapp.com>
- Fix race condition in _CmapTelemetry: remove shared _conn_created_start
  and _checkout_start slots; connection_ready now takes creation_time from
  AsyncConnection.creation_time, checkout_started returns the start time
  and checkout_succeeded/failed accept it as a parameter
- Move SRV monitor failure log into _telemetry.py as log_srv_monitor_failure
- Add _log_retry helper to _ClientConnectionRetryable to deduplicate
  log_command_retry call sites
- Fix _ServerSelectionTelemetry.failed to accept live topology_description
  at failure time instead of using the stale snapshot from construction
- Restore original _raise_if_not_ready and _get_conn parameter names/order
- Add docstrings to all public methods on _CmapTelemetry and _SdamTelemetry
- Remove redundant _publish/_listener/_events attrs from Server.__init__
- Avoid creating two _ServerSelectionTelemetry per select_server call by
  threading ss through select_servers and _select_server
- Make _ServerSelectionTelemetry.failed topology_description a required arg
- Move SRV monitor failure log to telemetry.py (log_srv_monitor_failure)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
dependabot Bot and others added 19 commits July 6, 2026 07:37
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…ongodb#2801)

Co-authored-by: Steven Silvester <steve.silvester@mongodb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants