Skip to content

Commit

Permalink
Inject log fields in ctx for grpc logs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielseibel1 committed Jun 14, 2024
1 parent b089c0f commit e1b5a6b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/bjartek/underflow"
"github.com/enescakir/emoji"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/runtime/ast"
Expand Down Expand Up @@ -532,6 +533,7 @@ func (o *OverflowState) InitializeContracts(ctx context.Context) *OverflowState

// GetAccount takes the account name and returns the state of that account on the given network.
func (o *OverflowState) GetAccount(ctx context.Context, key string) (*flow.Account, error) {
ctx = logging.InjectLogField(ctx, "account_name", key)
account, err := o.AccountE(key)
if err != nil {
return nil, err
Expand Down Expand Up @@ -651,12 +653,17 @@ func (o *OverflowState) GetLatestBlock(ctx context.Context) (*flow.Block, error)

// get block at a given height
func (o *OverflowState) GetBlockAtHeight(ctx context.Context, height uint64) (*flow.Block, error) {
ctx = logging.InjectLogField(ctx, "block_height", height)
bc := flowkit.BlockQuery{Height: height}
return o.Flowkit.GetBlock(ctx, bc)
// TODO: every get method should be decorated with this logging fields injection
// create PRs against main and v1.0
// on find-core, have a test for that (or wait for bjarte)
}

// blockId should be a hexadecimal string
func (o *OverflowState) GetBlockById(ctx context.Context, blockId string) (*flow.Block, error) {
ctx = logging.InjectLogField(ctx, "block_id", blockId)
bid := flow.HexToID(blockId)
bc := flowkit.BlockQuery{ID: &bid}
return o.Flowkit.GetBlock(ctx, bc)
Expand Down

0 comments on commit e1b5a6b

Please sign in to comment.