Skip to content

Commit 30764fb

Browse files
committed
Centralize incoming request logging in monitoring
Move the log_incoming_request helper from proxy/service.rs into monitoring/service.rs and call it at the start of NodeService::handle_request. Remove the duplicate implementation and the call from ProxyRequestService. Also add user_agent to an existing log entry in monitoring/service.rs. This centralizes request logging (including RPC method details for JsonRpc requests) and removes redundant code in the proxy service.
1 parent c66dbf7 commit 30764fb

2 files changed

Lines changed: 31 additions & 27 deletions

File tree

core/apps/dynode/src/monitoring/service.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ impl NodeService {
101101
}
102102

103103
pub async fn handle_request(&self, request: ProxyRequest) -> Result<ProxyResponse, Box<dyn Error + Send + Sync>> {
104+
Self::log_incoming_request(&request);
105+
104106
let chain_config = self.get_chain_config(&request)?;
105107
if !self.chain_types.allows(chain_config, request.request_type()) {
106108
return Self::request_not_allowed_response(&request);
@@ -180,6 +182,34 @@ impl NodeService {
180182
self.log_and_create_error_response(&request, None, UPSTREAMS_FAILED, last_error_data)
181183
}
182184

185+
fn log_incoming_request(request: &ProxyRequest) {
186+
let request_type = request.request_type();
187+
188+
match request_type {
189+
RequestType::JsonRpc(_) => {
190+
info_with_fields!(
191+
"Incoming request",
192+
id = request.id.as_str(),
193+
chain = request.chain.as_ref(),
194+
method = request.method.as_str(),
195+
uri = request.path.as_str(),
196+
rpc_method = &request_type.get_methods_list(),
197+
user_agent = request.user_agent.as_str(),
198+
);
199+
}
200+
RequestType::Regular { .. } => {
201+
info_with_fields!(
202+
"Incoming request",
203+
id = request.id.as_str(),
204+
chain = request.chain.as_ref(),
205+
method = request.method.as_str(),
206+
uri = request.path.as_str(),
207+
user_agent = request.user_agent.as_str(),
208+
);
209+
}
210+
}
211+
}
212+
183213
fn get_chain_config(&self, request: &ProxyRequest) -> Result<&ChainConfig, Box<dyn Error + Send + Sync>> {
184214
self.chains.get(&request.chain).ok_or_else(|| format!("Chain {} not configured", request.chain).into())
185215
}
@@ -207,6 +237,7 @@ impl NodeService {
207237
chain = request.chain.as_ref(),
208238
method = request.method.as_str(),
209239
uri = request.path.as_str(),
240+
user_agent = request.user_agent.as_str(),
210241
request = &request.request_type().get_methods_list(),
211242
);
212243

core/apps/dynode/src/proxy/service.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,6 @@ impl ProxyRequestService {
9797
headers
9898
}
9999

100-
fn log_incoming_request(request: &ProxyRequest, request_type: &RequestType) {
101-
let request_id = request.id.as_str();
102-
let chain = request.chain.as_ref();
103-
let method = request.method.as_str();
104-
let uri = request.path.as_str();
105-
let user_agent = request.user_agent.as_str();
106-
107-
match request_type {
108-
RequestType::JsonRpc(_) => {
109-
info_with_fields!(
110-
"Incoming request",
111-
id = request_id,
112-
chain = chain,
113-
method = method,
114-
uri = uri,
115-
rpc_method = &request_type.get_methods_list(),
116-
user_agent = user_agent,
117-
);
118-
}
119-
RequestType::Regular { .. } => {
120-
info_with_fields!("Incoming request", id = request_id, chain = chain, method = method, uri = uri, user_agent = user_agent,);
121-
}
122-
}
123-
}
124-
125100
fn add_proxy_response_metrics(metrics: &Metrics, request: &ProxyRequest, methods_for_metrics: &[String], host: &str, status: u16) {
126101
for method_name in methods_for_metrics {
127102
metrics.add_proxy_response(request.chain.as_ref(), method_name, host, status, request.elapsed().as_millis());
@@ -143,8 +118,6 @@ impl ProxyRequestService {
143118

144119
self.metrics.add_proxy_request(request.chain.as_ref());
145120

146-
Self::log_incoming_request(&request, request_type);
147-
148121
let cache_ttl = self.cache.should_cache_request(&chain, request_type);
149122
let cache_key = cache_ttl.and_then(|_| request_type.cache_key(&request.host, &request.path_with_query));
150123
let inflight_key = self

0 commit comments

Comments
 (0)