diff --git a/pkg/eth/api.go b/pkg/eth/api.go index 6df2fe29..9cdd3e20 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -170,8 +170,6 @@ func (pea *PublicEthAPI) BlockNumber() hexutil.Uint64 { // * When fullTx is true all transactions in the block are returned, otherwise // only the transaction hash is returned. func (pea *PublicEthAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { - ctx = context.WithValue(ctx, log.CtxKeyBlockNumber, number.Int64()) - log.Debugx(ctx, "getBlockByNumber") block, err := pea.B.BlockByNumber(ctx, number) if block != nil && err == nil { return pea.rpcMarshalBlock(block, true, fullTx) @@ -190,8 +188,6 @@ func (pea *PublicEthAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockN // GetBlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full // detail, otherwise only the transaction hash is returned. func (pea *PublicEthAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error) { - ctx = context.WithValue(ctx, log.CtxKeyBlockHash, hash.Hex()) - log.Debugx(ctx, "getBlockByHash") block, err := pea.B.BlockByHash(ctx, hash) if block != nil && err == nil { return pea.rpcMarshalBlock(block, true, fullTx) diff --git a/pkg/log/log.go b/pkg/log/log.go index 90d60be5..47e6136f 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -13,15 +13,16 @@ import ( ) const ( - CtxKeyUniqId = "id" CtxKeyApiMethod = "api_method" CtxKeyApiParams = "api_params" CtxKeyApiReqId = "api_reqid" - CtxKeyUserId = "user_id" + CtxKeyBlockHash = "block_hash" + CtxKeyBlockNumber = "block_num" CtxKeyConn = "conn" CtxKeyDuration = "duration" - CtxKeyBlockNumber = "block_num" - CtxKeyBlockHash = "block_hash" + CtxKeyError = "err" + CtxKeyUniqId = "uuid" + CtxKeyUserId = "user_id" ) // TODO: Allow registering arbitrary keys. @@ -33,6 +34,7 @@ var registeredKeys = []string{ CtxKeyBlockNumber, CtxKeyConn, CtxKeyDuration, + CtxKeyError, CtxKeyUniqId, CtxKeyUserId, } diff --git a/pkg/prom/middleware.go b/pkg/prom/middleware.go index bbefb2d9..0fcdb430 100644 --- a/pkg/prom/middleware.go +++ b/pkg/prom/middleware.go @@ -69,11 +69,11 @@ func prepareRequest(r *http.Request) (*http.Request, error) { // Pull out the method name, request ID, user ID, and address info. reqId := fmt.Sprintf("%g", result[jsonReqId]) reqMethod := fmt.Sprintf("%v", result[jsonMethod]) - reqParams, _ := json.Marshal(result[jsonParams]) + reqParams := fmt.Sprintf("%v", result[jsonParams]) // Truncate parameters unless trace logging is enabled. if !log.IsLevelEnabled(log.TraceLevel) { - if len(reqParams) > 100 { - reqParams = reqParams[:100] + if len(reqParams) > 250 { + reqParams = reqParams[:250] + "..." } } userId := r.Header.Get(headerUserId) @@ -86,7 +86,7 @@ func prepareRequest(r *http.Request) (*http.Request, error) { ctx := r.Context() ctx = context.WithValue(ctx, log.CtxKeyUniqId, uniqId.String()) ctx = context.WithValue(ctx, log.CtxKeyApiMethod, reqMethod) - ctx = context.WithValue(ctx, log.CtxKeyApiMethod, reqParams) + ctx = context.WithValue(ctx, log.CtxKeyApiParams, string(reqParams)) ctx = context.WithValue(ctx, log.CtxKeyApiReqId, reqId) ctx = context.WithValue(ctx, log.CtxKeyUserId, userId) ctx = context.WithValue(ctx, log.CtxKeyConn, conn) diff --git a/test/integration_suite_test.go b/test/integration_suite_test.go index f8c7c979..e6307814 100644 --- a/test/integration_suite_test.go +++ b/test/integration_suite_test.go @@ -4,9 +4,9 @@ import ( "io/ioutil" "testing" + "github.com/cerc-io/ipld-eth-server/v4/pkg/log" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/sirupsen/logrus" ) func TestIntegration(t *testing.T) { @@ -15,5 +15,5 @@ func TestIntegration(t *testing.T) { } var _ = BeforeSuite(func() { - logrus.SetOutput(ioutil.Discard) + log.SetOutput(ioutil.Discard) })