Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging #50

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions service/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,22 @@ func createProxyRequestMiddleware(next http.Handler, config config.Config, servi
req := r.Context().Value(DecodedRequestContextKey)
decodedReq, ok := (req).(*decode.EVMRPCRequestEnvelope)
if !ok {
var bodyCopy bytes.Buffer
tee := io.TeeReader(r.Body, &bodyCopy)
// read all body from reader into bodyBytes, and copy into bodyCopy
bodyBytes, err := io.ReadAll(tee)
if err != nil {
serviceLogger.Error().Err(err).Msg("can't read lrw.body")
}

// replace empty body reader with fresh copy
r.Body = io.NopCloser(&bodyCopy)

serviceLogger.Logger.Error().
Str("method", r.Method).
Str("url", r.URL.String()).
Str("host", r.Host).
Str("body", string(bodyBytes)).
Msg("can't cast request to *EVMRPCRequestEnvelope type")

// if we can't get decoded request then assign it empty structure to avoid panics
Expand Down
Loading