Skip to content

Commit

Permalink
feat: track if rpc response returned data
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw committed Jun 7, 2024
1 parent 3b07a20 commit 1d29a70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/eth/rpc/rpc_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::eth::primitives::SoliditySignature;
use crate::eth::primitives::TransactionInput;
use crate::eth::rpc::next_rpc_param;
use crate::eth::rpc::parse_rpc_rlp;
use crate::if_else;
#[cfg(feature = "metrics")]
use crate::infra::metrics;

Expand Down Expand Up @@ -121,13 +122,15 @@ impl<F: Future<Output = MethodResponse>> Future for RpcResponse<F> {
let elapsed = proj.start.elapsed();

// trace response
let response_success = response.is_success();
let response_result = response.as_result();
tracing::info!(
id = %proj.id,
method = %proj.method,
function = %proj.function.clone().unwrap_or_default(),
duration_us = %elapsed.as_micros(),
success = %response.is_success(),
result = %response.as_result(),
success = %response_success,
result = %response_result,
"rpc response"
);

Expand All @@ -136,7 +139,12 @@ impl<F: Future<Output = MethodResponse>> Future for RpcResponse<F> {
{
let active = ACTIVE_REQUESTS.fetch_sub(1, Ordering::Relaxed) - 1;
metrics::set_rpc_requests_active(active, proj.method.clone(), proj.function.clone());
metrics::inc_rpc_requests_finished(elapsed, proj.method.clone(), proj.function.clone(), response.is_success());

let mut rpc_result = "error";
if response_success {
rpc_result = if_else!(response_result.contains("\"result\":null"), "missing", "present");
}
metrics::inc_rpc_requests_finished(elapsed, proj.method.clone(), proj.function.clone(), rpc_result, response.is_success());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/infra/metrics/metrics_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metrics! {
counter rpc_requests_started{method, function} [],

"Number of JSON-RPC requests that finished."
histogram_duration rpc_requests_finished{method, function, success} [],
histogram_duration rpc_requests_finished{method, function, result, success} [],

"Number of JSON-RPC subscriptions active right now."
gauge rpc_subscriptions_active{subscription} []
Expand Down

0 comments on commit 1d29a70

Please sign in to comment.