From 71be1ef9f0b1293b8d2bdc716d5678b8aa14645d Mon Sep 17 00:00:00 2001 From: Stephan D Date: Thu, 25 Dec 2025 21:01:37 +0100 Subject: [PATCH] extended logging --- .../service/gateway/commands/transfer/fee.go | 22 +++++++++---------- .../service/gateway/rpcclient/clients.go | 15 ++++++------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go b/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go index e662e07..52dac2b 100644 --- a/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go +++ b/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go @@ -24,11 +24,11 @@ func NewEstimateTransfer(deps Deps) *estimateTransferFeeCommand { func (c *estimateTransferFeeCommand) Execute(ctx context.Context, req *chainv1.EstimateTransferFeeRequest) gsresponse.Responder[chainv1.EstimateTransferFeeResponse] { if err := c.deps.EnsureRepository(ctx); err != nil { - c.deps.Logger.Warn("repository unavailable", zap.Error(err)) + c.deps.Logger.Warn("Repository unavailable", zap.Error(err)) return gsresponse.Unavailable[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err) } if req == nil { - c.deps.Logger.Warn("nil request") + c.deps.Logger.Warn("Empty request received") return gsresponse.InvalidArgument[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, merrors.InvalidArgument("request is required")) } @@ -46,42 +46,42 @@ func (c *estimateTransferFeeCommand) Execute(ctx context.Context, req *chainv1.E sourceWallet, err := c.deps.Storage.Wallets().Get(ctx, sourceWalletRef) if err != nil { if errors.Is(err, merrors.ErrNoData) { - c.deps.Logger.Warn("source wallet not found", zap.String("source_wallet_ref", sourceWalletRef)) + c.deps.Logger.Warn("Source wallet not found", zap.String("source_wallet_ref", sourceWalletRef)) return gsresponse.NotFound[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err) } - c.deps.Logger.Warn("storage get wallet failed", zap.Error(err), zap.String("source_wallet_ref", sourceWalletRef)) + c.deps.Logger.Warn("Storage get wallet failed", zap.Error(err), zap.String("source_wallet_ref", sourceWalletRef)) return gsresponse.Auto[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err) } networkKey := strings.ToLower(strings.TrimSpace(sourceWallet.Network)) networkCfg, ok := c.deps.Networks.Network(networkKey) if !ok { - c.deps.Logger.Warn("unsupported chain", zap.String("network", networkKey)) + c.deps.Logger.Warn("Unsupported chain", zap.String("network", networkKey)) return gsresponse.InvalidArgument[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, merrors.InvalidArgument("unsupported chain for wallet")) } if c.deps.Drivers == nil { - c.deps.Logger.Warn("chain drivers missing", zap.String("network", networkKey)) + c.deps.Logger.Warn("Chain drivers missing", zap.String("network", networkKey)) return gsresponse.Internal[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, merrors.Internal("chain drivers not configured")) } chainDriver, err := c.deps.Drivers.Driver(networkKey) if err != nil { - c.deps.Logger.Warn("unsupported chain driver", zap.String("network", networkKey), zap.Error(err)) + c.deps.Logger.Warn("Unsupported chain driver", zap.String("network", networkKey), zap.Error(err)) return gsresponse.InvalidArgument[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, merrors.InvalidArgument("unsupported chain for wallet")) } dest, err := resolveDestination(ctx, c.deps, req.GetDestination(), sourceWallet) if err != nil { if errors.Is(err, merrors.ErrNoData) { - c.deps.Logger.Warn("destination not found", zap.String("destination_wallet_ref", req.GetDestination().GetManagedWalletRef())) + c.deps.Logger.Warn("Destination not found", zap.String("destination_wallet_ref", req.GetDestination().GetManagedWalletRef())) return gsresponse.NotFound[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err) } - c.deps.Logger.Warn("invalid destination", zap.Error(err)) + c.deps.Logger.Warn("Invalid destination", zap.Error(err)) return gsresponse.InvalidArgument[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err) } destinationAddress, err := destinationAddress(ctx, c.deps, chainDriver, dest) if err != nil { - c.deps.Logger.Warn("failed to resolve destination address", zap.Error(err)) + c.deps.Logger.Warn("Failed to resolve destination address", zap.Error(err)) return gsresponse.InvalidArgument[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err) } @@ -101,7 +101,7 @@ func (c *estimateTransferFeeCommand) Execute(ctx context.Context, req *chainv1.E } feeMoney, err := chainDriver.EstimateFee(ctx, driverDeps, networkCfg, walletForFee, destinationAddress, amount) if err != nil { - c.deps.Logger.Warn("fee estimation failed", zap.Error(err)) + c.deps.Logger.Warn("Fee estimation failed", zap.Error(err)) return gsresponse.Auto[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err) } diff --git a/api/gateway/chain/internal/service/gateway/rpcclient/clients.go b/api/gateway/chain/internal/service/gateway/rpcclient/clients.go index 6dff514..ddc0bfa 100644 --- a/api/gateway/chain/internal/service/gateway/rpcclient/clients.go +++ b/api/gateway/chain/internal/service/gateway/rpcclient/clients.go @@ -71,7 +71,7 @@ func Prepare(ctx context.Context, logger mlogger.Logger, networks []shared.Netwo cancel() if err != nil { result.Close() - clientLogger.Warn("failed to dial rpc endpoint", append(fields, zap.Error(err))...) + clientLogger.Warn("Failed to dial rpc endpoint", append(fields, zap.Error(err))...) return nil, merrors.Internal(fmt.Sprintf("rpc dial failed for %s: %s", name, err.Error())) } client := ethclient.NewClient(rpcCli) @@ -79,7 +79,7 @@ func Prepare(ctx context.Context, logger mlogger.Logger, networks []shared.Netwo eth: client, rpc: rpcCli, } - clientLogger.Info("rpc client ready", fields...) + clientLogger.Info("RPC client ready", fields...) } if len(result.clients) == 0 { @@ -95,12 +95,12 @@ func Prepare(ctx context.Context, logger mlogger.Logger, networks []shared.Netwo // Client returns a prepared client for the given network name. func (c *Clients) Client(network string) (*ethclient.Client, error) { if c == nil { - return nil, merrors.Internal("rpc clients not initialised") + return nil, merrors.Internal("RPC clients not initialised") } name := strings.ToLower(strings.TrimSpace(network)) entry, ok := c.clients[name] if !ok || entry.eth == nil { - return nil, merrors.InvalidArgument(fmt.Sprintf("rpc client not configured for network %s", name)) + return nil, merrors.InvalidArgument(fmt.Sprintf("RPC client not configured for network %s", name)) } return entry.eth, nil } @@ -130,7 +130,7 @@ func (c *Clients) Close() { entry.eth.Close() } if c.logger != nil { - c.logger.Info("rpc client closed", zap.String("network", name)) + c.logger.Info("RPC client closed", zap.String("network", name)) } } } @@ -156,16 +156,15 @@ func (l *loggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, erro fields := []zap.Field{ zap.String("network", l.network), - zap.String("rpc_endpoint", l.endpoint), } if len(reqBody) > 0 { fields = append(fields, zap.String("rpc_request", truncate(string(reqBody), 2048))) } - l.logger.Debug("rpc request", fields...) + l.logger.Debug("RPC request", fields...) resp, err := l.base.RoundTrip(req) if err != nil { - l.logger.Warn("rpc http request failed", append(fields, zap.Error(err))...) + l.logger.Warn("RPC http request failed", append(fields, zap.Error(err))...) return nil, err }