improved logging in callbacks

This commit is contained in:
Stephan D
2026-03-03 01:07:35 +01:00
parent b10ec79fe0
commit bae4cd6e35
45 changed files with 226 additions and 146 deletions

View File

@@ -11,7 +11,7 @@ import (
const (
paymentTypeAccount pkgmodel.PaymentType = 8
maxPrivateMethodResolutionDepth = 8
maxPrivateMethodResolutionDepth int = 8
)
func (s *Service) GetPaymentMethodPrivate(ctx context.Context, req *methodsv1.GetPaymentMethodPrivateRequest) (*methodsv1.GetPaymentMethodPrivateResponse, error) {

View File

@@ -8,6 +8,7 @@ import (
np "github.com/tech/sendico/pkg/messaging/notifications/processor"
nm "github.com/tech/sendico/pkg/model/notification"
"github.com/tech/sendico/pkg/mservice"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -62,25 +63,25 @@ func (s *Service) onRecipientNotification(
if err != nil {
s.logger.Warn("Failed to cascade archive payment methods by recipient",
zap.Error(err),
zap.String("recipient_ref", recipientRef.Hex()),
zap.String("actor_account_ref", actorAccountRef.Hex()))
mzap.ObjRef("recipient_ref", recipientRef),
mzap.ObjRef("actor_account_ref", actorAccountRef))
return err
}
s.logger.Info("Recipient archive cascade applied to payment methods",
zap.String("recipient_ref", recipientRef.Hex()),
zap.String("actor_account_ref", actorAccountRef.Hex()),
mzap.ObjRef("recipient_ref", recipientRef),
mzap.ObjRef("actor_account_ref", actorAccountRef),
zap.Int("updated_count", updated))
case nm.NADeleted:
if err := s.pmstore.DeleteByRecipient(ctx, recipientRef); err != nil {
s.logger.Warn("Failed to cascade delete payment methods by recipient",
zap.Error(err),
zap.String("recipient_ref", recipientRef.Hex()),
zap.String("actor_account_ref", actorAccountRef.Hex()))
mzap.ObjRef("recipient_ref", recipientRef),
mzap.ObjRef("actor_account_ref", actorAccountRef))
return err
}
s.logger.Info("Recipient delete cascade applied to payment methods",
zap.String("recipient_ref", recipientRef.Hex()),
zap.String("actor_account_ref", actorAccountRef.Hex()))
mzap.ObjRef("recipient_ref", recipientRef),
mzap.ObjRef("actor_account_ref", actorAccountRef))
}
return nil

View File

@@ -9,6 +9,7 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
pm "github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -24,7 +25,7 @@ type svc struct {
func (s *svc) Create(in Input) (payment *Payment, err error) {
logger := s.logger
logger.Debug("Starting Create",
zap.String("organization_ref", in.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", in.OrganizationRef),
zap.String("quotation_ref", strings.TrimSpace(in.QuotationRef)),
zap.Int("steps_count", len(in.Steps)),
)

View File

@@ -10,6 +10,7 @@ import (
"github.com/tech/sendico/payments/storage/model"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.uber.org/zap"
)
@@ -26,7 +27,7 @@ func (s *svc) TryReuse(
) (payment *model.Payment, reused bool, err error) {
logger := s.logger
logger.Debug("Starting Try reuse",
zap.String("organization_ref", in.OrganizationID.Hex()),
mzap.ObjRef("organization_ref", payment.OrganizationRef),
zap.Bool("has_idempotency_key", strings.TrimSpace(in.IdempotencyKey) != ""),
)
defer func(start time.Time) {

View File

@@ -12,6 +12,7 @@ import (
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/prepo"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -61,7 +62,7 @@ func newService(deps Dependencies) (Service, error) {
func (s *svc) GetPayment(ctx context.Context, in GetPaymentInput) (payment *agg.Payment, err error) {
logger := s.logger
logger.Debug("Starting Get payment",
zap.String("organization_ref", in.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", in.OrganizationRef),
zap.String("payment_ref", strings.TrimSpace(in.PaymentRef)),
)
defer func(start time.Time) {
@@ -93,7 +94,7 @@ func (s *svc) GetPayment(ctx context.Context, in GetPaymentInput) (payment *agg.
func (s *svc) ListPayments(ctx context.Context, in ListPaymentsInput) (out *ListPaymentsOutput, err error) {
logger := s.logger
logger.Debug("Starting List payments",
zap.String("organization_ref", in.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", in.OrganizationRef),
zap.String("quotation_ref", strings.TrimSpace(in.QuotationRef)),
zap.Int("states_count", len(in.States)),
zap.Int32("limit", in.Limit),

View File

@@ -175,13 +175,13 @@ func (s *svc) GetByPaymentRef(ctx context.Context, orgRef bson.ObjectID, payment
logger := s.logger
requestPaymentRef := strings.TrimSpace(paymentRef)
logger.Debug("Starting Get by payment ref",
zap.String("organization_ref", orgRef.Hex()),
mzap.ObjRef("organization_ref", orgRef),
zap.String("payment_ref", requestPaymentRef),
)
defer func(start time.Time) {
fields := []zap.Field{
zap.Int64("duration_ms", time.Since(start).Milliseconds()),
zap.String("organization_ref", orgRef.Hex()),
mzap.ObjRef("organization_ref", orgRef),
zap.String("payment_ref", requestPaymentRef),
}
if payment != nil {
@@ -225,7 +225,7 @@ func (s *svc) GetByPaymentRefGlobal(ctx context.Context, paymentRef string) (pay
}
if payment != nil {
fields = append(fields,
zap.String("organization_ref", payment.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", payment.OrganizationRef),
zap.String("state", string(payment.State)),
zap.Uint64("version", payment.Version),
)
@@ -253,7 +253,7 @@ func (s *svc) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, ide
logger := s.logger
hasKey := strings.TrimSpace(idempotencyKey) != ""
logger.Debug("Starting Get by idempotency key",
zap.String("organization_ref", orgRef.Hex()),
mzap.ObjRef("organization_ref", orgRef),
zap.Bool("has_idempotency_key", hasKey),
)
defer func(start time.Time) {
@@ -298,7 +298,7 @@ func (s *svc) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, ide
func (s *svc) ListByQuotationRef(ctx context.Context, in ListByQuotationRefInput) (out *ListOutput, err error) {
logger := s.logger
logger.Debug("Starting List by quotation ref",
zap.String("organization_ref", in.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", in.OrganizationRef),
zap.String("quotation_ref", strings.TrimSpace(in.QuotationRef)),
zap.Int32("limit", in.Limit),
)
@@ -337,7 +337,7 @@ func (s *svc) ListByQuotationRef(ctx context.Context, in ListByQuotationRefInput
func (s *svc) ListByState(ctx context.Context, in ListByStateInput) (out *ListOutput, err error) {
logger := s.logger
logger.Debug("Starting List by state",
zap.String("organization_ref", in.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", in.OrganizationRef),
zap.String("state", string(in.State)),
zap.Int32("limit", in.Limit),
)

View File

@@ -5,12 +5,13 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
"github.com/tech/sendico/pkg/discovery"
"sort"
"strconv"
"strings"
"time"
"github.com/tech/sendico/pkg/discovery"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/agg"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/batchmeta"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/idem"
@@ -60,8 +61,8 @@ func (s *svc) ExecuteBatchPayment(ctx context.Context, req *orchestrationv2.Exec
}
resolved, err := s.quote.ResolveAll(ctx, s.quoteStore, qsnap.ResolveAllInput{
OrganizationID: requestCtx.OrganizationID,
QuotationRef: requestCtx.QuotationRef,
OrganizationRef: requestCtx.OrganizationID,
QuotationRef: requestCtx.QuotationRef,
})
if err != nil {
return nil, remapResolveError(err)

View File

@@ -11,6 +11,7 @@ import (
pon "github.com/tech/sendico/pkg/messaging/notifications/paymentorchestrator"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.uber.org/zap"
)
@@ -64,7 +65,7 @@ func (p *brokerPaymentStatusPublisher) Publish(_ context.Context, in paymentStat
if paymentRef == "" || payment.OrganizationRef.IsZero() {
p.logger.Warn("Skipping payment status publish due to missing identifiers",
zap.String("payment_ref", paymentRef),
zap.String("organization_ref", payment.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", payment.OrganizationRef),
)
return nil
}

View File

@@ -36,8 +36,8 @@ type Output struct {
// ResolveAllInput defines lookup scope for resolving all items in a batch quotation.
type ResolveAllInput struct {
OrganizationID bson.ObjectID
QuotationRef string
OrganizationRef bson.ObjectID
QuotationRef string
}
// ResolveAllOutput contains all resolved items from a batch quotation.

View File

@@ -41,8 +41,8 @@ func TestResolveAll_BatchReturnsAllItems(t *testing.T) {
return record, nil
},
}, ResolveAllInput{
OrganizationID: orgID,
QuotationRef: "batch-quote-ref",
OrganizationRef: orgID,
QuotationRef: "batch-quote-ref",
})
if err != nil {
t.Fatalf("ResolveAll returned error: %v", err)
@@ -94,8 +94,8 @@ func TestResolveAll_SingleShapeReturnsOneItem(t *testing.T) {
return record, nil
},
}, ResolveAllInput{
OrganizationID: orgID,
QuotationRef: "single-quote-ref",
OrganizationRef: orgID,
QuotationRef: "single-quote-ref",
})
if err != nil {
t.Fatalf("ResolveAll returned error: %v", err)
@@ -137,8 +137,8 @@ func TestResolveAll_NonExecutableItemFails(t *testing.T) {
return record, nil
},
}, ResolveAllInput{
OrganizationID: orgID,
QuotationRef: "batch-mixed",
OrganizationRef: orgID,
QuotationRef: "batch-mixed",
})
if err == nil {
t.Fatal("expected error for non-executable item")
@@ -172,8 +172,8 @@ func TestResolveAll_ExpiredQuoteFails(t *testing.T) {
return record, nil
},
}, ResolveAllInput{
OrganizationID: orgID,
QuotationRef: "expired-quote",
OrganizationRef: orgID,
QuotationRef: "expired-quote",
})
if err == nil {
t.Fatal("expected error for expired quote")
@@ -187,8 +187,8 @@ func TestResolveAll_EmptyQuotationRefFails(t *testing.T) {
resolver := New(Dependencies{Logger: zap.NewNop()})
_, err := resolver.ResolveAll(context.Background(), &fakeStore{}, ResolveAllInput{
OrganizationID: bson.NewObjectID(),
QuotationRef: "",
OrganizationRef: bson.NewObjectID(),
QuotationRef: "",
})
if err == nil {
t.Fatal("expected error for empty quotation_ref")
@@ -199,8 +199,8 @@ func TestResolveAll_QuoteNotFoundFails(t *testing.T) {
resolver := New(Dependencies{Logger: zap.NewNop()})
_, err := resolver.ResolveAll(context.Background(), &fakeStore{}, ResolveAllInput{
OrganizationID: bson.NewObjectID(),
QuotationRef: "nonexistent",
OrganizationRef: bson.NewObjectID(),
QuotationRef: "nonexistent",
})
if err == nil {
t.Fatal("expected error for not-found quote")
@@ -234,8 +234,8 @@ func TestResolveAll_SetsQuoteRefWhenEmpty(t *testing.T) {
return record, nil
},
}, ResolveAllInput{
OrganizationID: orgID,
QuotationRef: "batch-ref",
OrganizationRef: orgID,
QuotationRef: "batch-ref",
})
if err != nil {
t.Fatalf("ResolveAll returned error: %v", err)

View File

@@ -11,6 +11,7 @@ import (
quotestorage "github.com/tech/sendico/payments/storage/quote"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -33,7 +34,7 @@ func (s *svc) Resolve(
) (out *Output, err error) {
logger := s.logger
logger.Debug("Starting Resolve",
zap.String("organization_ref", in.OrganizationID.Hex()),
mzap.ObjRef("organization_ref", in.OrganizationID),
zap.String("quotation_ref", strings.TrimSpace(in.QuotationRef)),
)
defer func(start time.Time) {
@@ -105,7 +106,7 @@ func (s *svc) ResolveAll(
) (out *ResolveAllOutput, err error) {
logger := s.logger
logger.Debug("Starting ResolveAll",
zap.String("organization_ref", in.OrganizationID.Hex()),
mzap.ObjRef("organization_ref", in.OrganizationRef),
zap.String("quotation_ref", strings.TrimSpace(in.QuotationRef)),
)
defer func(start time.Time) {
@@ -126,7 +127,7 @@ func (s *svc) ResolveAll(
if store == nil {
return nil, merrors.InvalidArgument("quotes store is required")
}
if in.OrganizationID.IsZero() {
if in.OrganizationRef.IsZero() {
return nil, merrors.InvalidArgument("organization_id is required")
}
quoteRef := strings.TrimSpace(in.QuotationRef)
@@ -134,7 +135,7 @@ func (s *svc) ResolveAll(
return nil, merrors.InvalidArgument("quotation_ref is required")
}
record, err := store.GetByRef(ctx, in.OrganizationID, quoteRef)
record, err := store.GetByRef(ctx, in.OrganizationRef, quoteRef)
if err != nil {
if errors.Is(err, quotestorage.ErrQuoteNotFound) || errors.Is(err, merrors.ErrNoData) {
return nil, ErrQuoteNotFound

View File

@@ -3,10 +3,12 @@ package orchestrator
import (
"context"
"errors"
"github.com/tech/sendico/pkg/discovery"
"strings"
"time"
"github.com/tech/sendico/pkg/discovery"
"github.com/tech/sendico/pkg/mutil/mzap"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/agg"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/erecon"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/prepo"
@@ -111,7 +113,7 @@ func (s *Service) onPaymentGatewayExecution(ctx context.Context, msg *pmodel.Pay
s.logger.Debug("Reconciling payment from gateway execution event",
zap.String("payment_ref", strings.TrimSpace(payment.PaymentRef)),
zap.String("organization_ref", payment.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", payment.OrganizationRef),
zap.String("step_ref", strings.TrimSpace(event.StepRef)),
zap.String("status", strings.TrimSpace(string(event.Status))),
zap.String("transfer_ref", strings.TrimSpace(event.TransferRef)),
@@ -457,7 +459,7 @@ func (s *Service) pollObserveCandidate(ctx context.Context, payment *agg.Payment
s.logger.Debug("Reconciling payment from observe polling result",
zap.String("payment_ref", strings.TrimSpace(payment.PaymentRef)),
zap.String("organization_ref", payment.OrganizationRef.Hex()),
mzap.ObjRef("organization_ref", payment.OrganizationRef),
zap.String("step_ref", candidate.stepRef),
zap.String("status", strings.TrimSpace(string(event.Status))),
zap.String("transfer_ref", candidate.transferRef),

View File

@@ -5,6 +5,7 @@ import (
"strings"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
endpointv1 "github.com/tech/sendico/pkg/proto/payments/endpoint/v1"
quotationv2 "github.com/tech/sendico/pkg/proto/payments/quotation/v2"
@@ -33,7 +34,7 @@ type quoteIntentLogSummary struct {
func (s *QuotationServiceV2) quotePaymentLogger(req *quotationv2.QuotePaymentRequest) mlogger.Logger {
return s.logger.With(
zap.String("flow_ref", bson.NewObjectID().Hex()),
mzap.ObjRef("flow_ref", bson.NewObjectID()),
zap.String("rpc_method", "QuotePayment"),
zap.String("organization_ref", strings.TrimSpace(req.GetMeta().GetOrganizationRef())),
zap.String("idempotency_key", strings.TrimSpace(req.GetIdempotencyKey())),
@@ -44,7 +45,7 @@ func (s *QuotationServiceV2) quotePaymentLogger(req *quotationv2.QuotePaymentReq
func (s *QuotationServiceV2) quotePaymentsLogger(req *quotationv2.QuotePaymentsRequest) mlogger.Logger {
return s.logger.With(
zap.String("flow_ref", bson.NewObjectID().Hex()),
mzap.ObjRef("flow_ref", bson.NewObjectID()),
zap.String("rpc_method", "QuotePayments"),
zap.String("organization_ref", strings.TrimSpace(req.GetMeta().GetOrganizationRef())),
zap.String("idempotency_key", strings.TrimSpace(req.GetIdempotencyKey())),