Skip to content

Commit

Permalink
remove all zerolog .Trace logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pspencer-arculus committed Jul 3, 2023
1 parent e169f06 commit 07e7a83
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
35 changes: 17 additions & 18 deletions v2/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package hedera

import (
"context"
"encoding/hex"
"os"
"time"

Expand All @@ -41,7 +40,7 @@ import (
"google.golang.org/grpc/status"
)

var logCtx zerolog.Logger
// var logCtx zerolog.Logger

// A required init function to setup logging at the correct level
func init() { // nolint
Expand All @@ -62,7 +61,7 @@ func init() { // nolint
zerolog.SetGlobalLevel(zerolog.Disabled)
}

logCtx = log.With().Str("module", "hedera-sdk-go").Logger()
// logCtx = log.With().Str("module", "hedera-sdk-go").Logger()
}

const maxAttempts = 10
Expand Down Expand Up @@ -121,7 +120,7 @@ func _Execute( // nolint

var attempt int64
var errPersistent error
var marshaledRequest []byte
// var marshaledRequest []byte

for attempt = int64(0); attempt < int64(maxAttempts); attempt, *currentBackoff = attempt+1, *currentBackoff*2 {
var protoRequest interface{}
Expand All @@ -138,7 +137,7 @@ func _Execute( // nolint
return TransactionResponse{}, ErrInvalidNodeAccountIDSet{nodeAccountID}
}

marshaledRequest, _ = protobuf.Marshal(protoRequest.(*services.Transaction))
// marshaledRequest, _ = protobuf.Marshal(protoRequest.(*services.Transaction))
} else if query, ok := request.(*Query); ok {
if query.nodeAccountIDs.locked && query.nodeAccountIDs._Length() > 0 {
protoRequest = makeRequest(request)
Expand Down Expand Up @@ -168,21 +167,21 @@ func _Execute( // nolint
query.nodeAccountIDs._Set(0, node.accountID)
protoRequest = makeRequest(request)
}
marshaledRequest, _ = protobuf.Marshal(protoRequest.(*services.Query))
// marshaledRequest, _ = protobuf.Marshal(protoRequest.(*services.Query))
}

node._InUse()

logCtx.Trace().Str("requestId", logID).Str("nodeAccountID", node.accountID.String()).Str("nodeIPAddress", node.address._String()).
Str("Request Proto:", hex.EncodeToString(marshaledRequest)).Msg("executing")
// logCtx.Trace().Str("requestId", logID).Str("nodeAccountID", node.accountID.String()).Str("nodeIPAddress", node.address._String()).
// Str("Request Proto:", hex.EncodeToString(marshaledRequest)).Msg("executing")

if !node._IsHealthy() {
logCtx.Trace().Str("requestId", logID).Str("delay", node._Wait().String()).Msg("node is unhealthy, waiting before continuing")
// logCtx.Trace().Str("requestId", logID).Str("delay", node._Wait().String()).Msg("node is unhealthy, waiting before continuing")
_DelayForAttempt(logID, backOff.NextBackOff(), attempt)
continue
}

logCtx.Trace().Str("requestId", logID).Msg("updating node account ID index")
// logCtx.Trace().Str("requestId", logID).Msg("updating node account ID index")

channel, err := node._GetChannel()
if err != nil {
Expand All @@ -203,18 +202,18 @@ func _Execute( // nolint
ctx, cancel = context.WithDeadline(ctx, grpcDeadline)
}

logCtx.Trace().Str("requestId", logID).Msg("executing gRPC call")
// logCtx.Trace().Str("requestId", logID).Msg("executing gRPC call")

var marshaledResponse []byte
// var marshaledResponse []byte
if method.query != nil {
resp, err = method.query(ctx, protoRequest.(*services.Query))
if err == nil {
marshaledResponse, _ = protobuf.Marshal(resp.(*services.Response))
// marshaledResponse, _ = protobuf.Marshal(resp.(*services.Response))
}
} else {
resp, err = method.transaction(ctx, protoRequest.(*services.Transaction))
if err == nil {
marshaledResponse, _ = protobuf.Marshal(resp.(*services.TransactionResponse))
// marshaledResponse, _ = protobuf.Marshal(resp.(*services.TransactionResponse))
}
}

Expand Down Expand Up @@ -247,7 +246,7 @@ func _Execute( // nolint
case executionStateExpired:
if transaction, ok := request.(*Transaction); ok {
if !client.GetOperatorAccountID()._IsZero() && transaction.regenerateTransactionID && !transaction.transactionIDs.locked {
logCtx.Trace().Str("requestId", logID).Msg("received `TRANSACTION_EXPIRED` with transaction ID regeneration enabled; regenerating")
// logCtx.Trace().Str("requestId", logID).Msg("received `TRANSACTION_EXPIRED` with transaction ID regeneration enabled; regenerating")
transaction.transactionIDs._Set(transaction.transactionIDs.index, TransactionIDGenerate(client.GetOperatorAccountID()))
if err != nil {
panic(err)
Expand All @@ -266,7 +265,7 @@ func _Execute( // nolint

return &services.Response{}, mapStatusError(request, resp)
case executionStateFinished:
logCtx.Trace().Str("Response Proto:", hex.EncodeToString(marshaledResponse)).Msg("finished")
// logCtx.Trace().Str("Response Proto:", hex.EncodeToString(marshaledResponse)).Msg("finished")

return mapResponse(request, resp, node.accountID, protoRequest)
}
Expand All @@ -284,13 +283,13 @@ func _Execute( // nolint
}

func _DelayForAttempt(logID string, backoff time.Duration, attempt int64) {
logCtx.Trace().Str("requestId", logID).Dur("delay", backoff).Int64("attempt", attempt+1).Msg("retrying request attempt")
// logCtx.Trace().Str("requestId", logID).Dur("delay", backoff).Int64("attempt", attempt+1).Msg("retrying request attempt")
time.Sleep(backoff)
}

func _ExecutableDefaultRetryHandler(logID string, err error) bool {
code := status.Code(err)
logCtx.Trace().Str("requestId", logID).Str("status", code.String()).Msg("received gRPC error with status code")
// logCtx.Trace().Str("requestId", logID).Str("status", code.String()).Msg("received gRPC error with status code")
switch code {
case codes.ResourceExhausted, codes.Unavailable:
return true
Expand Down
2 changes: 1 addition & 1 deletion v2/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (this *Query) SetMaxRetry(count int) *Query {
}

func _QueryShouldRetry(logID string, status Status) _ExecutionState {
logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("query precheck status received")
// logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("query precheck status received")
switch status {
case StatusPlatformTransactionNotCreated, StatusPlatformNotActive, StatusBusy:
return executionStateRetry
Expand Down
2 changes: 1 addition & 1 deletion v2/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ func (this *Transaction) _KeyAlreadySigned(

func _TransactionShouldRetry(logID string, _ interface{}, response interface{}) _ExecutionState {
status := Status(response.(*services.TransactionResponse).NodeTransactionPrecheckCode)
logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("transaction precheck status received")
// logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("transaction precheck status received")
switch status {
case StatusPlatformTransactionNotCreated, StatusPlatformNotActive, StatusBusy:
return executionStateRetry
Expand Down
4 changes: 2 additions & 2 deletions v2/transaction_receipt_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (query *TransactionReceiptQuery) GetCost(client *Client) (Hbar, error) {

func _TransactionReceiptQueryShouldRetry(logID string, request interface{}, response interface{}) _ExecutionState {
status := Status(response.(*services.Response).GetTransactionGetReceipt().GetHeader().GetNodeTransactionPrecheckCode())
logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("receipt precheck status received")
// logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("receipt precheck status received")

switch status {
case StatusPlatformTransactionNotCreated, StatusBusy, StatusUnknown, StatusReceiptNotFound, StatusRecordNotFound:
Expand All @@ -194,7 +194,7 @@ func _TransactionReceiptQueryShouldRetry(logID string, request interface{}, resp
}

status = Status(response.(*services.Response).GetTransactionGetReceipt().GetReceipt().GetStatus())
logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("receipt status received")
// logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("receipt status received")

switch status {
case StatusBusy, StatusUnknown, StatusOk, StatusReceiptNotFound, StatusRecordNotFound:
Expand Down
4 changes: 2 additions & 2 deletions v2/transaction_record_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (query *TransactionRecordQuery) GetCost(client *Client) (Hbar, error) {

func _TransactionRecordQueryShouldRetry(logID string, request interface{}, response interface{}) _ExecutionState {
status := Status(response.(*services.Response).GetTransactionGetRecord().GetHeader().GetNodeTransactionPrecheckCode())
logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("precheck status received")
// logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("precheck status received")

switch status {
case StatusPlatformTransactionNotCreated, StatusBusy, StatusUnknown, StatusReceiptNotFound, StatusRecordNotFound:
Expand All @@ -197,7 +197,7 @@ func _TransactionRecordQueryShouldRetry(logID string, request interface{}, respo
}

status = Status(response.(*services.Response).GetTransactionGetRecord().GetTransactionRecord().GetReceipt().GetStatus())
logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("record's receipt status received")
// logCtx.Trace().Str("requestId", logID).Str("status", status.String()).Msg("record's receipt status received")

switch status {
case StatusBusy, StatusUnknown, StatusOk, StatusReceiptNotFound, StatusRecordNotFound:
Expand Down

0 comments on commit 07e7a83

Please sign in to comment.