From b17e6eba5c07f1012cd321151f357c19448c5858 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Thu, 10 Oct 2024 08:21:43 -0400 Subject: [PATCH 1/5] trace [slt-330] [goreleaser] --- services/omnirpc/http/client.go | 1 + .../omnirpc/modules/receiptsbackup/receiptsbackup.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/services/omnirpc/http/client.go b/services/omnirpc/http/client.go index a5e1647014..c07ffaeb77 100644 --- a/services/omnirpc/http/client.go +++ b/services/omnirpc/http/client.go @@ -12,6 +12,7 @@ type Client interface { } // Request is a request builder. +// TODO: this needs to support tracing. type Request interface { // SetBody sets the request body SetBody(body []byte) Request diff --git a/services/omnirpc/modules/receiptsbackup/receiptsbackup.go b/services/omnirpc/modules/receiptsbackup/receiptsbackup.go index d10b999ca2..0700ccd53e 100644 --- a/services/omnirpc/modules/receiptsbackup/receiptsbackup.go +++ b/services/omnirpc/modules/receiptsbackup/receiptsbackup.go @@ -137,11 +137,18 @@ func (r *receiptsProxyImpl) ProxyRequest(c *gin.Context) (err error) { } func (r *receiptsProxyImpl) processRequest(ctx context.Context, rpcRequest rpc.Request, requestID []byte) (resp omniHTTP.Response, err error) { + ctx, span := r.handler.Tracer().Start(ctx, "proxyrequest") + defer func() { + metrics.EndSpanWithErr(span, err) + }() + mixins.TxSubmitMixin(ctx, r.handler, rpcRequest) req := r.client.NewRequest() body, err := json.Marshal(rpcRequest) + span.AddEvent("request marshalled", trace.WithAttributes(attribute.String("body", string(body)))) + //nolint: exhaustive switch client.RPCMethod(rpcRequest.Method) { case client.TransactionReceiptByHashMethod: @@ -192,6 +199,8 @@ func (r *receiptsProxyImpl) processRequest(ctx context.Context, rpcRequest rpc.R return nil, fmt.Errorf("could not get response from RPC %s: %w", r.proxyURL, err) } + span.AddEvent("response returned", trace.WithAttributes(attribute.String("body", string(resp.Body())))) + return resp, nil } } From 3ad23c2593de7e093a164f8fed197f13bf13fc56 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Thu, 10 Oct 2024 09:08:55 -0400 Subject: [PATCH 2/5] fix marshal --- services/omnirpc/modules/receiptsbackup/receiptsbackup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/omnirpc/modules/receiptsbackup/receiptsbackup.go b/services/omnirpc/modules/receiptsbackup/receiptsbackup.go index 0700ccd53e..f472d40105 100644 --- a/services/omnirpc/modules/receiptsbackup/receiptsbackup.go +++ b/services/omnirpc/modules/receiptsbackup/receiptsbackup.go @@ -147,7 +147,7 @@ func (r *receiptsProxyImpl) processRequest(ctx context.Context, rpcRequest rpc.R req := r.client.NewRequest() body, err := json.Marshal(rpcRequest) - span.AddEvent("request marshalled", trace.WithAttributes(attribute.String("body", string(body)))) + span.AddEvent("request marshaled", trace.WithAttributes(attribute.String("body", string(body)))) //nolint: exhaustive switch client.RPCMethod(rpcRequest.Method) { From d325d3fe57abc58a9c643be1b97cafdc648fcded Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Thu, 10 Oct 2024 10:05:21 -0400 Subject: [PATCH 3/5] marshal to bin [goreleaser] --- ethergo/util/attributes.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ethergo/util/attributes.go b/ethergo/util/attributes.go index 38b1ff2d0f..57feb9cfc6 100644 --- a/ethergo/util/attributes.go +++ b/ethergo/util/attributes.go @@ -22,6 +22,7 @@ const ( gasPriceAttr = "tx.GasPrice" gasFeeCapAttr = "tx.GasFeeCap" gasTipCapAttr = "tx.GasTipCap" + txRawAttr = "tx.Raw" ) // TxToAttributes converts a transaction to a slice of attribute.KeyValue. @@ -33,6 +34,12 @@ func TxToAttributes(transaction *types.Transaction) []attribute.KeyValue { } else { from = call.From.Hex() } + + bin, err := transaction.MarshalBinary() + if err != nil { + bin = []byte(fmt.Sprintf("could not be marshalled: %v", err)) + } + var attributes = []attribute.KeyValue{ attribute.String(hashAttr, transaction.Hash().Hex()), attribute.String(fromAttr, from), @@ -46,6 +53,7 @@ func TxToAttributes(transaction *types.Transaction) []attribute.KeyValue { // nolint: gosec attribute.Int64(gasLimitAttr, int64(transaction.Gas())), attribute.String(chainIDAttr, BigPtrToString(transaction.ChainId())), + attribute.String(txRawAttr, common.Bytes2Hex(bin))), } if transaction.Type() == types.LegacyTxType && transaction.GasPrice() != nil { From 24785c9eda8caf9526ae41bb31147bec3a79beae Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Thu, 10 Oct 2024 11:00:47 -0400 Subject: [PATCH 4/5] syntax --- ethergo/util/attributes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethergo/util/attributes.go b/ethergo/util/attributes.go index 57feb9cfc6..c4a4165830 100644 --- a/ethergo/util/attributes.go +++ b/ethergo/util/attributes.go @@ -36,7 +36,7 @@ func TxToAttributes(transaction *types.Transaction) []attribute.KeyValue { } bin, err := transaction.MarshalBinary() - if err != nil { + if err != nil { bin = []byte(fmt.Sprintf("could not be marshalled: %v", err)) } @@ -53,7 +53,7 @@ func TxToAttributes(transaction *types.Transaction) []attribute.KeyValue { // nolint: gosec attribute.Int64(gasLimitAttr, int64(transaction.Gas())), attribute.String(chainIDAttr, BigPtrToString(transaction.ChainId())), - attribute.String(txRawAttr, common.Bytes2Hex(bin))), + attribute.String(txRawAttr, common.Bytes2Hex(bin)), } if transaction.Type() == types.LegacyTxType && transaction.GasPrice() != nil { From 0b2dc8e41363b76bd64c7d038f6faa3e0f2546c4 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Thu, 10 Oct 2024 11:08:04 -0400 Subject: [PATCH 5/5] another test --- ethergo/util/attributes.go | 2 +- ethergo/util/attributes_test.go | 4 ++++ ethergo/util/export_test.go | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ethergo/util/attributes.go b/ethergo/util/attributes.go index c4a4165830..8c3ae1e1d9 100644 --- a/ethergo/util/attributes.go +++ b/ethergo/util/attributes.go @@ -37,7 +37,7 @@ func TxToAttributes(transaction *types.Transaction) []attribute.KeyValue { bin, err := transaction.MarshalBinary() if err != nil { - bin = []byte(fmt.Sprintf("could not be marshalled: %v", err)) + bin = []byte(fmt.Sprintf("could not be marshaled: %v", err)) } var attributes = []attribute.KeyValue{ diff --git a/ethergo/util/attributes_test.go b/ethergo/util/attributes_test.go index 7c91b200d4..b8aebaf3a4 100644 --- a/ethergo/util/attributes_test.go +++ b/ethergo/util/attributes_test.go @@ -109,6 +109,10 @@ func (u *UtilSuite) TestTxToAttributesDynamicTX() { u.Require().Equal(mapAttr[util.GasFeeCapAttr].AsString(), mockTX.GasFeeCap().String()) u.Require().Equal(mapAttr[util.GasTipCapAttr].AsString(), mockTX.GasTipCap().String()) + marshaled, err := mockTX.MarshalBinary() + u.Require().NoError(err) + + u.Require().Equal(mapAttr[util.TxRawAttr].AsString(), common.Bytes2Hex(marshaled)) _, hasGasPrice := mapAttr[util.GasPriceAttr] u.Require().False(hasGasPrice) u.Require().NotNil(mapAttr[util.FromAttr]) diff --git a/ethergo/util/export_test.go b/ethergo/util/export_test.go index fc357be3ab..e19a5bff5a 100644 --- a/ethergo/util/export_test.go +++ b/ethergo/util/export_test.go @@ -72,4 +72,6 @@ const ( GasFeeCapAttr = gasFeeCapAttr // GasTipCapAttr exports gasTipCapAttr for testing. GasTipCapAttr = gasTipCapAttr + // TxRawAttr exports txRawAttr for testing. + TxRawAttr = txRawAttr )