This commit is contained in:
Thomas E Lackey 2023-01-20 14:27:12 -06:00
parent c2a5b012cf
commit bb39cac1eb
4 changed files with 12 additions and 14 deletions

View File

@ -170,8 +170,6 @@ func (pea *PublicEthAPI) BlockNumber() hexutil.Uint64 {
// * When fullTx is true all transactions in the block are returned, otherwise // * When fullTx is true all transactions in the block are returned, otherwise
// only the transaction hash is returned. // only the transaction hash is returned.
func (pea *PublicEthAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { 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) block, err := pea.B.BlockByNumber(ctx, number)
if block != nil && err == nil { if block != nil && err == nil {
return pea.rpcMarshalBlock(block, true, fullTx) 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 // 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. // detail, otherwise only the transaction hash is returned.
func (pea *PublicEthAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error) { 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) block, err := pea.B.BlockByHash(ctx, hash)
if block != nil && err == nil { if block != nil && err == nil {
return pea.rpcMarshalBlock(block, true, fullTx) return pea.rpcMarshalBlock(block, true, fullTx)

View File

@ -13,15 +13,16 @@ import (
) )
const ( const (
CtxKeyUniqId = "id"
CtxKeyApiMethod = "api_method" CtxKeyApiMethod = "api_method"
CtxKeyApiParams = "api_params" CtxKeyApiParams = "api_params"
CtxKeyApiReqId = "api_reqid" CtxKeyApiReqId = "api_reqid"
CtxKeyUserId = "user_id" CtxKeyBlockHash = "block_hash"
CtxKeyBlockNumber = "block_num"
CtxKeyConn = "conn" CtxKeyConn = "conn"
CtxKeyDuration = "duration" CtxKeyDuration = "duration"
CtxKeyBlockNumber = "block_num" CtxKeyError = "err"
CtxKeyBlockHash = "block_hash" CtxKeyUniqId = "uuid"
CtxKeyUserId = "user_id"
) )
// TODO: Allow registering arbitrary keys. // TODO: Allow registering arbitrary keys.
@ -33,6 +34,7 @@ var registeredKeys = []string{
CtxKeyBlockNumber, CtxKeyBlockNumber,
CtxKeyConn, CtxKeyConn,
CtxKeyDuration, CtxKeyDuration,
CtxKeyError,
CtxKeyUniqId, CtxKeyUniqId,
CtxKeyUserId, CtxKeyUserId,
} }

View File

@ -69,11 +69,11 @@ func prepareRequest(r *http.Request) (*http.Request, error) {
// Pull out the method name, request ID, user ID, and address info. // Pull out the method name, request ID, user ID, and address info.
reqId := fmt.Sprintf("%g", result[jsonReqId]) reqId := fmt.Sprintf("%g", result[jsonReqId])
reqMethod := fmt.Sprintf("%v", result[jsonMethod]) reqMethod := fmt.Sprintf("%v", result[jsonMethod])
reqParams, _ := json.Marshal(result[jsonParams]) reqParams := fmt.Sprintf("%v", result[jsonParams])
// Truncate parameters unless trace logging is enabled. // Truncate parameters unless trace logging is enabled.
if !log.IsLevelEnabled(log.TraceLevel) { if !log.IsLevelEnabled(log.TraceLevel) {
if len(reqParams) > 100 { if len(reqParams) > 250 {
reqParams = reqParams[:100] reqParams = reqParams[:250] + "..."
} }
} }
userId := r.Header.Get(headerUserId) userId := r.Header.Get(headerUserId)
@ -86,7 +86,7 @@ func prepareRequest(r *http.Request) (*http.Request, error) {
ctx := r.Context() ctx := r.Context()
ctx = context.WithValue(ctx, log.CtxKeyUniqId, uniqId.String()) ctx = context.WithValue(ctx, log.CtxKeyUniqId, uniqId.String())
ctx = context.WithValue(ctx, log.CtxKeyApiMethod, reqMethod) 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.CtxKeyApiReqId, reqId)
ctx = context.WithValue(ctx, log.CtxKeyUserId, userId) ctx = context.WithValue(ctx, log.CtxKeyUserId, userId)
ctx = context.WithValue(ctx, log.CtxKeyConn, conn) ctx = context.WithValue(ctx, log.CtxKeyConn, conn)

View File

@ -4,9 +4,9 @@ import (
"io/ioutil" "io/ioutil"
"testing" "testing"
"github.com/cerc-io/ipld-eth-server/v4/pkg/log"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
) )
func TestIntegration(t *testing.T) { func TestIntegration(t *testing.T) {
@ -15,5 +15,5 @@ func TestIntegration(t *testing.T) {
} }
var _ = BeforeSuite(func() { var _ = BeforeSuite(func() {
logrus.SetOutput(ioutil.Discard) log.SetOutput(ioutil.Discard)
}) })