Skip to content

Commit ffde190

Browse files
committed
server/json-rpc: Log connection info with JSON-RPC call
1 parent 58b0f25 commit ffde190

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

server/json-rpc/src/handlers.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ pub async fn jsonrpc_handler<R: SubgraphRegistrar>(
3939
headers: HeaderMap,
4040
body: String,
4141
) -> impl IntoResponse {
42-
// Log the incoming request with proxy headers
43-
info!(
44-
&state.logger,
45-
"JSON-RPC request";
46-
"remote_addr" => %remote_addr,
47-
"x_forwarded_for" => headers.get("x-forwarded-for").and_then(|v| v.to_str().ok()),
48-
"x_real_ip" => headers.get("x-real-ip").and_then(|v| v.to_str().ok()),
49-
"x_forwarded_proto" => headers.get("x-forwarded-proto").and_then(|v| v.to_str().ok())
50-
);
42+
fn header<'a>(headers: &'a HeaderMap, key: &str) -> &'a str {
43+
headers
44+
.get(key)
45+
.and_then(|v| v.to_str().ok())
46+
.unwrap_or("unset")
47+
}
5148

5249
// Parse the JSON-RPC request
5350
let request: JsonRpcRequest = match serde_json::from_str(&body) {
@@ -69,7 +66,11 @@ pub async fn jsonrpc_handler<R: SubgraphRegistrar>(
6966
&state.logger,
7067
"JSON-RPC call";
7168
"method" => &request.method,
72-
"params" => ?request.params
69+
"params" => ?request.params,
70+
"remote_addr" => %remote_addr,
71+
"x_forwarded_for" => header(&headers, "x-forwarded-for"),
72+
"x_real_ip" => header(&headers, "x-real-ip"),
73+
"x_forwarded_proto" => header(&headers, "x-forwarded-proto")
7374
);
7475

7576
// Dispatch to the appropriate handler

0 commit comments

Comments
 (0)