better logging
This commit is contained in:
@@ -2,6 +2,7 @@ package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -20,9 +21,9 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
|
||||
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
|
||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
"github.com/tech/sendico/pkg/server/grpcapp"
|
||||
"go.uber.org/zap"
|
||||
@@ -69,9 +70,10 @@ type Service struct {
|
||||
}
|
||||
|
||||
func NewService(logger mlogger.Logger, repo storage.Repository, producer msg.Producer, broker mb.Broker, cfg Config) *Service {
|
||||
if logger != nil {
|
||||
logger = logger.Named("tgsettle_gateway")
|
||||
if logger == nil {
|
||||
logger = zap.NewNop()
|
||||
}
|
||||
logger = logger.Named("service")
|
||||
svc := &Service{
|
||||
logger: logger,
|
||||
repo: repo,
|
||||
@@ -126,7 +128,7 @@ func (s *Service) consumeProcessor(processor np.EnvelopeProcessor) {
|
||||
}
|
||||
s.consumers = append(s.consumers, consumer)
|
||||
go func() {
|
||||
if err := consumer.ConsumeMessages(processor.Process); err != nil {
|
||||
if err := consumer.ConsumeMessages(processor.Process); err != nil && !errors.Is(err, context.Canceled) {
|
||||
s.logger.Warn("Messaging consumer stopped", zap.Error(err), zap.String("event", processor.GetSubject().ToString()))
|
||||
}
|
||||
}()
|
||||
@@ -211,7 +213,11 @@ func (s *Service) onIntent(ctx context.Context, intent *model.PaymentGatewayInte
|
||||
return err
|
||||
}
|
||||
if existing != nil {
|
||||
s.logger.Info("Payment gateway intent already executed", zap.String("idempotency_key", intent.IdempotencyKey))
|
||||
s.logger.Info("Payment gateway intent already executed",
|
||||
zap.String("idempotency_key", intent.IdempotencyKey),
|
||||
zap.String("payment_intent_id", intent.PaymentIntentID),
|
||||
zap.String("quote_ref", intent.QuoteRef),
|
||||
zap.String("rail", intent.OutgoingLeg))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -241,12 +247,19 @@ func (s *Service) onConfirmationResult(ctx context.Context, result *model.Confir
|
||||
}
|
||||
|
||||
if result.RawReply != nil && s.repo != nil && s.repo.TelegramConfirmations() != nil {
|
||||
_ = s.repo.TelegramConfirmations().Upsert(ctx, &storagemodel.TelegramConfirmation{
|
||||
if err := s.repo.TelegramConfirmations().Upsert(ctx, &storagemodel.TelegramConfirmation{
|
||||
RequestID: requestID,
|
||||
PaymentIntentID: intent.PaymentIntentID,
|
||||
QuoteRef: intent.QuoteRef,
|
||||
RawReply: result.RawReply,
|
||||
})
|
||||
}); err != nil {
|
||||
s.logger.Warn("Failed to store telegram confirmation", zap.Error(err), zap.String("request_id", requestID))
|
||||
} else {
|
||||
s.logger.Info("Stored telegram confirmation", zap.String("request_id", requestID),
|
||||
zap.String("payment_intent_id", intent.PaymentIntentID),
|
||||
zap.String("reply_text", result.RawReply.Text), zap.String("reply_user_id", result.RawReply.FromUserID),
|
||||
zap.String("reply_user", result.RawReply.FromUsername))
|
||||
}
|
||||
}
|
||||
|
||||
if result.Status == model.ConfirmationStatusConfirmed || result.Status == model.ConfirmationStatusClarified {
|
||||
@@ -305,7 +318,13 @@ func (s *Service) sendConfirmationRequest(request *model.ConfirmationRequest) er
|
||||
}
|
||||
env := confirmations.ConfirmationRequest(string(mservice.PaymentGateway), request)
|
||||
if err := s.producer.SendMessage(env); err != nil {
|
||||
s.logger.Warn("Failed to publish confirmation request", zap.Error(err), zap.String("request_id", request.RequestID))
|
||||
s.logger.Warn("Failed to publish confirmation request",
|
||||
zap.Error(err),
|
||||
zap.String("request_id", request.RequestID),
|
||||
zap.String("payment_intent_id", request.PaymentIntentID),
|
||||
zap.String("quote_ref", request.QuoteRef),
|
||||
zap.String("rail", request.Rail),
|
||||
zap.Int32("timeout_seconds", request.TimeoutSeconds))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -326,7 +345,13 @@ func (s *Service) publishExecution(intent *model.PaymentGatewayIntent, result *m
|
||||
}
|
||||
env := paymentgateway.PaymentGatewayExecution(string(mservice.PaymentGateway), exec)
|
||||
if err := s.producer.SendMessage(env); err != nil {
|
||||
s.logger.Warn("Failed to publish gateway execution result", zap.Error(err), zap.String("request_id", result.RequestID))
|
||||
s.logger.Warn("Failed to publish gateway execution result",
|
||||
zap.Error(err),
|
||||
zap.String("request_id", result.RequestID),
|
||||
zap.String("idempotency_key", intent.IdempotencyKey),
|
||||
zap.String("payment_intent_id", intent.PaymentIntentID),
|
||||
zap.String("quote_ref", intent.QuoteRef),
|
||||
zap.String("status", string(result.Status)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user