Skip to content

Commit fc43c53

Browse files
overflow 163 inject logging fields (#165)
* Inject log fields in ctx for grpc logs * Remove TODO item * Add more grpc logging fields to ctxs * Depend on grpc logging
1 parent 445011f commit fc43c53

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/bjartek/underflow v1.5.0
1010
github.com/enescakir/emoji v1.0.0
1111
github.com/fatih/color v1.16.0
12+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
1213
github.com/hashicorp/go-multierror v1.1.1
1314
github.com/hexops/autogold v1.3.1
1415
github.com/onflow/cadence v1.0.0-preview.34
@@ -95,7 +96,6 @@ require (
9596
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
9697
github.com/gorilla/websocket v1.5.0 // indirect
9798
github.com/gosuri/uilive v0.0.4 // indirect
98-
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
9999
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
100100
github.com/hashicorp/errwrap v1.1.0 // indirect
101101
github.com/hashicorp/golang-lru v1.0.2 // indirect

state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/bjartek/underflow"
1616
"github.com/enescakir/emoji"
17+
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
1718
"github.com/hashicorp/go-multierror"
1819
"github.com/onflow/cadence"
1920
"github.com/onflow/cadence/runtime"
@@ -497,6 +498,7 @@ func (o *OverflowState) GetAccount(ctx context.Context, key string) (*flow.Accou
497498
return nil, err
498499
}
499500
rawAddress := account.Address
501+
ctx = logging.InjectFields(ctx, logging.Fields{"account_name", key, "account_address", rawAddress.String()})
500502
return o.Flowkit.GetAccount(ctx, rawAddress)
501503
}
502504

@@ -611,12 +613,14 @@ func (o *OverflowState) GetLatestBlock(ctx context.Context) (*flow.Block, error)
611613

612614
// get block at a given height
613615
func (o *OverflowState) GetBlockAtHeight(ctx context.Context, height uint64) (*flow.Block, error) {
616+
ctx = logging.InjectLogField(ctx, "block_height", height)
614617
bc := flowkit.BlockQuery{Height: height}
615618
return o.Flowkit.GetBlock(ctx, bc)
616619
}
617620

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

transaction.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/bjartek/underflow"
10+
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
1011
"github.com/onflow/cadence/runtime/common"
1112
"github.com/onflow/cadence/runtime/parser"
1213
"github.com/onflow/flow-go-sdk"
@@ -144,6 +145,7 @@ func (o *OverflowState) CreateOverflowTransaction(blockId string, transactionRes
144145
}
145146

146147
func (o *OverflowState) GetOverflowTransactionById(ctx context.Context, id flow.Identifier) (*OverflowTransaction, error) {
148+
ctx = logging.InjectLogField(ctx, "transaction_id", id)
147149
tx, txr, err := o.Flowkit.GetTransactionByID(ctx, id, false)
148150
if err != nil {
149151
return nil, err
@@ -156,6 +158,7 @@ func (o *OverflowState) GetOverflowTransactionById(ctx context.Context, id flow.
156158
}
157159

158160
func (o *OverflowState) GetTransactionById(ctx context.Context, id flow.Identifier) (*flow.Transaction, error) {
161+
ctx = logging.InjectLogField(ctx, "transaction_id", id)
159162
tx, _, err := o.Flowkit.GetTransactionByID(ctx, id, false)
160163
if err != nil {
161164
return nil, err
@@ -164,6 +167,7 @@ func (o *OverflowState) GetTransactionById(ctx context.Context, id flow.Identifi
164167
}
165168

166169
func (o *OverflowState) GetTransactionsByBlockId(ctx context.Context, id flow.Identifier) ([]*flow.Transaction, []*flow.TransactionResult, error) {
170+
ctx = logging.InjectLogField(ctx, "block_id", id)
167171
tx, txr, err := o.Flowkit.GetTransactionsByBlockID(ctx, id)
168172
if err != nil {
169173
return nil, nil, err

0 commit comments

Comments
 (0)