UpstreamRPCProviderStatistics

Documentation for eth_defi.provider.rpc_proxy.UpstreamRPCProviderStatistics Python class.

class UpstreamRPCProviderStatistics

Bases: object

Per-provider statistics collected during proxy operation.

Tracks request counts, failure counts, and method-level breakdowns for each upstream RPC provider. Instances are keyed by provider URL in RPCProxy.provider_stats.

Attributes summary

url

Upstream RPC URL (with API keys stripped for safe logging)

request_count

Total number of requests forwarded to this provider

failure_count

Total number of failed requests (timeouts, HTTP errors, RPC errors)

last_failure

Timestamp of the last failure (naive UTC), or None if no failures

method_counts

Breakdown of requests by JSON-RPC method name.

method_failure_counts

Breakdown of failures by JSON-RPC method name

error_replies

List of error replies received from this provider.

Methods summary

__init__(url[, request_count, ...])

record_failure(method, error_summary[, ...])

Record a failed request to this provider.

record_request(method)

Record a request being sent to this provider.

url: str

Upstream RPC URL (with API keys stripped for safe logging)

request_count: int

Total number of requests forwarded to this provider

failure_count: int

Total number of failed requests (timeouts, HTTP errors, RPC errors)

last_failure: Optional[datetime.datetime]

Timestamp of the last failure (naive UTC), or None if no failures

method_counts: dict[str, int]

Breakdown of requests by JSON-RPC method name. e.g. {"eth_getBlockByNumber": 42, "eth_getBalance": 15}

method_failure_counts: dict[str, int]

Breakdown of failures by JSON-RPC method name

error_replies: list[dict]

List of error replies received from this provider. Each entry is a dict with keys: "timestamp" (naive UTC), "method" (JSON-RPC method), "http_status" (int or None), "error" (str summary — exception message, HTTP status text, or JSON-RPC error message). Capped at DEFAULT_MAX_ERROR_REPLIES to avoid unbounded growth.

record_request(method)

Record a request being sent to this provider.

Parameters

method (str) –

Return type

None

record_failure(method, error_summary, http_status=None, max_error_replies=100)

Record a failed request to this provider.

Parameters
  • method (str) –

  • error_summary (str) –

  • http_status (Optional[int]) –

  • max_error_replies (int) –

Return type

None

__init__(url, request_count=0, failure_count=0, last_failure=None, method_counts=<factory>, method_failure_counts=<factory>, error_replies=<factory>, _lock=<factory>)
Parameters
Return type

None