Skip to content

Commit

Permalink
Log failed requests only (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak authored Dec 18, 2023
1 parent 23bcc52 commit 7684cbd
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,7 @@ func isNil(i any) bool {
}

func (s *Server) handleRequest(ctx context.Context, req *Request) (*response, error) {
reqJSON, err := json.Marshal(req)
if err == nil {
s.log.Debugw("Serving RPC request", "request", string(reqJSON))
}

if err = req.isSane(); err != nil {
if err := req.isSane(); err != nil {
return nil, err
}

Expand All @@ -425,9 +420,7 @@ func (s *Server) handleRequest(ctx context.Context, req *Request) (*response, er
return res, nil
}
defer func() {
handlerTook := time.Since(handlerTimer)
s.listener.OnRequestHandled(req.Method, handlerTook)
s.log.Debugw("Responding to RPC request", "method", req.Method, "id", req.ID, "took", handlerTook)
s.listener.OnRequestHandled(req.Method, time.Since(handlerTimer))
}()

tuple := reflect.ValueOf(calledMethod.Handler).Call(args)
Expand All @@ -438,7 +431,10 @@ func (s *Server) handleRequest(ctx context.Context, req *Request) (*response, er
if errAny := tuple[1].Interface(); !isNil(errAny) {
res.Error = errAny.(*Error)
if res.Error.Code == InternalError {
s.listener.OnRequestFailed(req.Method, err)
s.listener.OnRequestFailed(req.Method, res.Error)
reqJSON, _ := json.Marshal(req)
errJSON, _ := json.Marshal(res.Error)
s.log.Debugw("Failed handing RPC request", "req", string(reqJSON), "res", string(errJSON))
}
return res, nil
}
Expand Down

0 comments on commit 7684cbd

Please sign in to comment.