diff --git a/ethergo/util/attributes.go b/ethergo/util/attributes.go index 38b1ff2d0f..8c3ae1e1d9 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 marshaled: %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 { 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 ) 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..f472d40105 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 marshaled", 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 } }