dank_mids.stats package

Submodules

dank_mids.stats.retry module

class dank_mids.stats.retry.StatsRetryObserver

Bases: object

Retry observer that records events into a stats collector.

When the provided collector lacks retry fields (for example, when the compiled stats module is imported), the observer falls back to an internal in-memory collector so retry handling does not raise AttributeError.

This observer intentionally does not auto-register itself. Wire it up explicitly via dank_mids.retry_observer.register_retry_observer().

__call__(event)

Call self as a function.

Parameters:

event (RetryEvent)

Return type:

None

__init__(collector=None)
Parameters:

collector (_RetryCollector | None)

Return type:

None

Module contents

stats.py

This module provides functionality for logging and collecting statistics related to the Dank Mids library. It includes custom logging levels, a specialized logger, and classes for collecting and writing statistics.

Key components: - Custom logging levels (STATS, DEVHINT) - _StatsLogger: A specialized logger for Dank Mids statistics - _Collector: Handles collection and computation of stats-related data - _Writer: Converts collected stats into human-readable format - _SentryExporter: Pushes metrics to Sentry

This module is crucial for debugging, performance monitoring, and optimization of the Dank Mids library.

dank_mids.stats.devhint(msg, *args, **kwargs)

Log a message with the DEVHINT logging level.

Parameters:
  • msg (str) – The message to log.

  • *args (Any) – Additional positional arguments for the logger.

  • **kwargs (Any) – Additional keyword arguments for the logger.

Return type:

None

Example

>>> _logger.devhint("This is a developer hint for debugging purposes")
dank_mids.stats.log(msg, *args, **kwargs)

Log a message with the STATS logging level.

Parameters:
  • msg (str) – The message to log.

  • *args (Any) – Additional positional arguments for the logger.

  • **kwargs (Any) – Additional keyword arguments for the logger.

Return type:

None

Example

>>> _logger.stats("Operation took %s seconds", 3.14)
dank_mids.stats.log_duration(work_descriptor, start, *, level=13)

Log the duration of a specific operation.

Parameters:
  • work_descriptor (str) – Description of the work being timed.

  • start (float) – Start time of the operation.

  • level (int) – Logging level to use. Defaults to STATS.

Return type:

None

dank_mids.stats.log_errd_batch(batch)

Log information about a failed JSON-RPC batch.

Parameters:

batch (JSONRPCBatch) – The failed batch to log.

Return type:

None

dank_mids.stats.COLLECT_STATS: bool = False

Flag to enable or disable stats collection.

dank_mids.stats.DEVHINT: Final = 15

Custom logging level for developer hints, between STATS and INFO.

dank_mids.stats.STATS: Final = 13

Custom logging level for statistics, between DEBUG and INFO.