diff --git a/src/eth/rpc/rpc_http_middleware.rs b/src/eth/rpc/rpc_http_middleware.rs index 1d244ff33..14ffc0b56 100644 --- a/src/eth/rpc/rpc_http_middleware.rs +++ b/src/eth/rpc/rpc_http_middleware.rs @@ -41,8 +41,8 @@ where /// Extracts the client application name from the `app` query parameter. fn parse_client_app(uri: &Uri) -> RpcClientApp { + // parse query params let Some(query_params_str) = uri.query() else { return RpcClientApp::Unknown }; - let query_params: HashMap = match serde_urlencoded::from_str(query_params_str) { Ok(url) => url, Err(e) => { @@ -51,8 +51,11 @@ fn parse_client_app(uri: &Uri) -> RpcClientApp { } }; - match query_params.get("app") { - Some(app) => RpcClientApp::Identified(app.to_owned()), - None => RpcClientApp::Unknown, + // try to extract client from query params + for param in ["app", "client"] { + if let Some(client_app) = query_params.get(param) { + return RpcClientApp::Identified(client_app.to_owned()); + } } + RpcClientApp::Unknown } diff --git a/src/eth/rpc/rpc_middleware.rs b/src/eth/rpc/rpc_middleware.rs index 5abcea5d7..81f067cdf 100644 --- a/src/eth/rpc/rpc_middleware.rs +++ b/src/eth/rpc/rpc_middleware.rs @@ -49,7 +49,7 @@ impl<'a> RpcServiceT<'a> for RpcMiddleware { fn call(&self, request: jsonrpsee::types::Request<'a>) -> Self::Future { // extract request data - let app = extract_client_app(&request); + let client = extract_client_app(&request); let method = request.method_name(); let function = match method { "eth_call" | "eth_estimateGas" => extract_call_function(request.params()), @@ -59,7 +59,7 @@ impl<'a> RpcServiceT<'a> for RpcMiddleware { // trace request tracing::info!( - %app, + %client, id = %request.id, %method, function = %function.clone().unwrap_or_default(), @@ -71,12 +71,12 @@ impl<'a> RpcServiceT<'a> for RpcMiddleware { #[cfg(feature = "metrics")] { let active = ACTIVE_REQUESTS.fetch_add(1, Ordering::Relaxed) + 1; - metrics::set_rpc_requests_active(active, &app, method, function.clone()); - metrics::inc_rpc_requests_started(&app, method, function.clone()); + metrics::set_rpc_requests_active(active, &client, method, function.clone()); + metrics::inc_rpc_requests_started(&client, method, function.clone()); } RpcResponse { - app, + client, id: request.id.to_string(), method: method.to_string(), function, @@ -96,7 +96,7 @@ pub struct RpcResponse<'a> { #[pin] future_response: ResponseFuture>, - app: RpcClientApp, + client: RpcClientApp, id: String, method: String, function: Option, @@ -119,7 +119,7 @@ impl<'a> Future for RpcResponse<'a> { let response_success = response.is_success(); let response_result = response.as_result(); tracing::info!( - app = %proj.app, + client = %proj.client, id = %proj.id, method = %proj.method, function = %proj.function.clone().unwrap_or_default(), @@ -133,7 +133,7 @@ impl<'a> Future for RpcResponse<'a> { #[cfg(feature = "metrics")] { let active = ACTIVE_REQUESTS.fetch_sub(1, Ordering::Relaxed) - 1; - metrics::set_rpc_requests_active(active, &*proj.app, proj.method.clone(), proj.function.clone()); + metrics::set_rpc_requests_active(active, &*proj.client, proj.method.clone(), proj.function.clone()); let mut rpc_result = "error"; if response_success { @@ -142,7 +142,7 @@ impl<'a> Future for RpcResponse<'a> { metrics::inc_rpc_requests_finished( elapsed, - &*proj.app, + &*proj.client, proj.method.clone(), proj.function.clone(), rpc_result, diff --git a/src/infra/metrics/metrics_definitions.rs b/src/infra/metrics/metrics_definitions.rs index 86d57fd27..0dc9f7038 100644 --- a/src/infra/metrics/metrics_definitions.rs +++ b/src/infra/metrics/metrics_definitions.rs @@ -5,16 +5,16 @@ metrics! { group: json_rpc, "Number of JSON-RPC requests active right now." - gauge rpc_requests_active{app, method, function} [], + gauge rpc_requests_active{client, method, function} [], "Number of JSON-RPC requests that started." - counter rpc_requests_started{app, method, function} [], + counter rpc_requests_started{client, method, function} [], "Number of JSON-RPC requests that finished." - histogram_duration rpc_requests_finished{app, method, function, result, success} [], + histogram_duration rpc_requests_finished{client, method, function, result, success} [], "Number of JSON-RPC subscriptions active right now." - gauge rpc_subscriptions_active{subscription} [] + gauge rpc_subscriptions_active{subscription} [] } // Storage reads.