diff --git a/api/billing/fees/internal/service/fees/internal/resolver/impl.go b/api/billing/fees/internal/service/fees/internal/resolver/impl.go index 0a595286..d1dbbcf3 100644 --- a/api/billing/fees/internal/service/fees/internal/resolver/impl.go +++ b/api/billing/fees/internal/service/fees/internal/resolver/impl.go @@ -50,19 +50,19 @@ func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *primitive.Obje if rule, selErr := selectRule(plan, trigger, at, attrs); selErr == nil { return plan, rule, nil } else if !errors.Is(selErr, ErrNoFeeRuleFound) { - r.logger.Warn("Failed selecting rule for org plan", zap.Error(selErr), zap.String("org_ref", orgRef.Hex())) + r.logger.Warn("Failed selecting rule for org plan", zap.Error(selErr), mzap.ObjRef("org_ref", *orgRef)) return nil, nil, selErr } - r.logger.Debug( - "No matching rule in org plan; falling back to global", + orgFields := []zap.Field{ mzap.ObjRef("org_ref", *orgRef), zap.String("trigger", string(trigger)), zap.Time("booked_at", at), zap.Any("attributes", attrs), - zapFieldsForPlan(plan)..., - ) + } + orgFields = append(orgFields, zapFieldsForPlan(plan)...) + r.logger.Debug("No matching rule in org plan; falling back to global", orgFields...) } else if !errors.Is(err, storage.ErrFeePlanNotFound) { - r.logger.Warn("Failed resolving org fee plan", zap.Error(err), zap.String("org_ref", orgRef.Hex())) + r.logger.Warn("Failed resolving org fee plan", zap.Error(err), mzap.ObjRef("org_ref", *orgRef)) return nil, nil, err } } @@ -84,9 +84,13 @@ func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *primitive.Obje if !errors.Is(err, ErrNoFeeRuleFound) { r.logger.Warn("Failed selecting rule in global plan", zap.Error(err)) } else { - r.logger.Debug("No matching rule in global plan", zap.String("trigger", string(trigger)), - zap.Time("booked_at", at), zap.Any("attributes", attrs), zapFieldsForPlan(plan)..., - ) + globalFields := []zap.Field{ + zap.String("trigger", string(trigger)), + zap.Time("booked_at", at), + zap.Any("attributes", attrs), + } + globalFields = append(globalFields, zapFieldsForPlan(plan)...) + r.logger.Debug("No matching rule in global plan", globalFields...) } return nil, nil, err } @@ -178,12 +182,12 @@ func zapFieldsForPlan(plan *model.FeePlan) []zap.Field { fields = append(fields, zap.Bool("plan_effective_to_set", false)) } if plan.OrganizationRef != nil && !plan.OrganizationRef.IsZero() { - fields = append(fields, zap.String("plan_org_ref", plan.OrganizationRef.Hex())) + fields = append(fields, mzap.ObjRef("plan_org_ref", *plan.OrganizationRef)) } else { fields = append(fields, zap.Bool("plan_org_ref_set", false)) } if plan.GetID() != nil && !plan.GetID().IsZero() { - fields = append(fields, zap.String("plan_id", plan.GetID().Hex())) + fields = append(fields, mzap.StorableRef(plan)) } return fields } diff --git a/api/billing/fees/internal/service/fees/service.go b/api/billing/fees/internal/service/fees/service.go index 5e28ee31..33cb92ad 100644 --- a/api/billing/fees/internal/service/fees/service.go +++ b/api/billing/fees/internal/service/fees/service.go @@ -412,7 +412,7 @@ func (s *Service) computeQuote(ctx context.Context, orgRef primitive.ObjectID, i return s.computeQuoteWithTime(ctx, orgRef, intent, overrides, trace, s.clock.Now()) } -func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef primitive.ObjectID, intent *feesv1.Intent, overrides *feesv1.PolicyOverrides, trace *tracev1.TraceContext, now time.Time) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) { +func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef primitive.ObjectID, intent *feesv1.Intent, _ *feesv1.PolicyOverrides, trace *tracev1.TraceContext, now time.Time) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) { bookedAt := now if intent.GetBookedAt() != nil && intent.GetBookedAt().IsValid() { bookedAt = intent.GetBookedAt().AsTime()