From 3803474079d68bf737b35056854bc6989efb87f7 Mon Sep 17 00:00:00 2001 From: Maksym Hrynenko Date: Sun, 19 May 2024 11:45:12 +0300 Subject: [PATCH 1/4] add: user-agent log to logger --- internal/service/api/handlers/create_identity.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/service/api/handlers/create_identity.go b/internal/service/api/handlers/create_identity.go index 86159e5..500cc6e 100644 --- a/internal/service/api/handlers/create_identity.go +++ b/internal/service/api/handlers/create_identity.go @@ -69,7 +69,10 @@ func CreateIdentity(w http.ResponseWriter, r *http.Request) { ape.RenderErr(w, problems.InternalError()) return } - log := Log(r).WithField("request_data", string(rawReqData)) + log := Log(r).WithFields(logan.F{ + "user-agent": r.Header.Get("User-Agent"), + "request_data": string(rawReqData), + }) algorithm := signatureAlgorithm(req.Data.DocumentSOD.Algorithm) if algorithm == "" { From 53ec77f6e9be2322df19edee4edebd9dd750fa04 Mon Sep 17 00:00:00 2001 From: Maksym Hrynenko Date: Sun, 19 May 2024 12:00:51 +0300 Subject: [PATCH 2/4] add: debug log to have logs in success request --- internal/service/api/handlers/create_identity.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/service/api/handlers/create_identity.go b/internal/service/api/handlers/create_identity.go index 500cc6e..6ad4624 100644 --- a/internal/service/api/handlers/create_identity.go +++ b/internal/service/api/handlers/create_identity.go @@ -74,6 +74,8 @@ func CreateIdentity(w http.ResponseWriter, r *http.Request) { "request_data": string(rawReqData), }) + log.Debug("create identity test") + algorithm := signatureAlgorithm(req.Data.DocumentSOD.Algorithm) if algorithm == "" { log.WithError(fmt.Errorf("%s is not a valid algorithm", req.Data.DocumentSOD.Algorithm)).Error("failed to select signature algorithm") From 4c5b1b6fa64caaec4785401cd88ec1ca18f4f3b7 Mon Sep 17 00:00:00 2001 From: Maksym Hrynenko Date: Sun, 19 May 2024 13:16:24 +0300 Subject: [PATCH 3/4] add: extended error logging with user-agent, user_did, block_number fields --- .../service/api/handlers/get_gist_data.go | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/internal/service/api/handlers/get_gist_data.go b/internal/service/api/handlers/get_gist_data.go index 4824a01..9c053d2 100644 --- a/internal/service/api/handlers/get_gist_data.go +++ b/internal/service/api/handlers/get_gist_data.go @@ -2,12 +2,11 @@ package handlers import ( "context" - validation "github.com/go-ozzo/ozzo-validation/v4" - "gitlab.com/distributed_lab/logan/v3/errors" "math/big" "net/http" "github.com/ethereum/go-ethereum/accounts/abi/bind" + validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/iden3/contracts-abi/state/go/abi" core "github.com/iden3/go-iden3-core/v2" "github.com/iden3/go-iden3-core/v2/w3c" @@ -16,40 +15,47 @@ import ( "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" "gitlab.com/distributed_lab/logan/v3" + "gitlab.com/distributed_lab/logan/v3/errors" ) func GetGistData(w http.ResponseWriter, r *http.Request) { req, err := requests.NewGetGistDataRequest(r) if err != nil { + Log(r).WithError(err).Error("failed to parse get gist data request") ape.RenderErr(w, problems.BadRequest(err)...) return } + log := Log(r).WithFields(logan.F{ + "user-agent": r.Header.Get("User-Agent"), + "user_did": req.UserDID, + "block_number": req.BlockNumber, + }) + userDID, err := w3c.ParseDID(req.UserDID) if err != nil { - Log(r).WithError(err).Error("failed to parse user DID") + log.WithError(err).Error("failed to parse user DID") ape.RenderErr(w, problems.BadRequest(err)...) return } userID, err := core.IDFromDID(*userDID) if err != nil { - Log(r).WithError(err).Error("failed to parse user ID") + log.WithError(err).Error("failed to parse user ID") ape.RenderErr(w, problems.InternalError()) return } blockNum, err := EthClient(r).BlockNumber(context.Background()) if err != nil { - Log(r).WithError(err).Error("failed to get block number") + log.WithError(err).Error("failed to get block number") ape.RenderErr(w, problems.InternalError()) return } if req.BlockNumber > blockNum { - Log(r).WithFields(logan.F{ - "requested_block_number": req.BlockNumber, - "latest_block_number": blockNum, + log.WithFields(logan.F{ + "latest_block_number": blockNum, }).Error("Requested block number is higher than latest") ape.RenderErr(w, problems.BadRequest(validation.Errors{ "/block_number": errors.New("Requested block number is higher than latest"), @@ -67,7 +73,7 @@ func GetGistData(w http.ResponseWriter, r *http.Request) { BlockNumber: new(big.Int).SetUint64(blockNum), }, userID.BigInt()) if err != nil { - Log(r).WithError(err).Error("failed to get GIST proof") + log.WithError(err).Error("failed to get GIST proof") ape.RenderErr(w, problems.InternalError()) return } @@ -76,13 +82,13 @@ func GetGistData(w http.ResponseWriter, r *http.Request) { BlockNumber: new(big.Int).SetUint64(blockNum), }) if err != nil { - Log(r).WithError(err).Error("failed to get GIST root") + log.WithError(err).Error("failed to get GIST root") ape.RenderErr(w, problems.InternalError()) return } if gistProof.Root.Cmp(gistRoot) != 0 { - Log(r).WithFields(logan.F{ + log.WithFields(logan.F{ "gist_root": gistRoot.String(), "gist_proof_root": gistProof.Root.String(), }).Warn("gist root does not match") From 879642ae22a877843c363225c0b23e9df94621e6 Mon Sep 17 00:00:00 2001 From: Maksym Hrynenko Date: Sun, 19 May 2024 13:17:23 +0300 Subject: [PATCH 4/4] remove: debug message --- internal/service/api/handlers/create_identity.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/service/api/handlers/create_identity.go b/internal/service/api/handlers/create_identity.go index 6ad4624..500cc6e 100644 --- a/internal/service/api/handlers/create_identity.go +++ b/internal/service/api/handlers/create_identity.go @@ -74,8 +74,6 @@ func CreateIdentity(w http.ResponseWriter, r *http.Request) { "request_data": string(rawReqData), }) - log.Debug("create identity test") - algorithm := signatureAlgorithm(req.Data.DocumentSOD.Algorithm) if algorithm == "" { log.WithError(fmt.Errorf("%s is not a valid algorithm", req.Data.DocumentSOD.Algorithm)).Error("failed to select signature algorithm")