improved logging in callbacks
This commit is contained in:
@@ -7,11 +7,14 @@ import (
|
||||
"github.com/tech/sendico/edge/callbacks/internal/model"
|
||||
"github.com/tech/sendico/edge/callbacks/internal/storage"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
repo storage.EndpointRepo
|
||||
logger mlogger.Logger
|
||||
repo storage.EndpointRepo
|
||||
}
|
||||
|
||||
// New creates endpoint resolver service.
|
||||
@@ -19,8 +22,15 @@ func New(deps Dependencies) (Resolver, error) {
|
||||
if deps.EndpointRepo == nil {
|
||||
return nil, merrors.InvalidArgument("subscriptions: endpoint repo is required", "endpointRepo")
|
||||
}
|
||||
logger := deps.Logger
|
||||
if logger == nil {
|
||||
logger = zap.NewNop()
|
||||
}
|
||||
|
||||
return &service{repo: deps.EndpointRepo}, nil
|
||||
return &service{
|
||||
logger: logger.Named("subscriptions"),
|
||||
repo: deps.EndpointRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *service) Resolve(ctx context.Context, eventType string, organizationRef bson.ObjectID) ([]model.Endpoint, error) {
|
||||
@@ -33,8 +43,19 @@ func (s *service) Resolve(ctx context.Context, eventType string, organizationRef
|
||||
|
||||
endpoints, err := s.repo.FindActive(ctx, eventType, organizationRef)
|
||||
if err != nil {
|
||||
s.logger.Warn("Failed to resolve active endpoints",
|
||||
zap.String("event_type", eventType),
|
||||
zap.String("organization_ref", organizationRef.Hex()),
|
||||
zap.Error(err),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.logger.Debug("Resolved active endpoints",
|
||||
zap.String("event_type", eventType),
|
||||
zap.String("organization_ref", organizationRef.Hex()),
|
||||
zap.Int("endpoints", len(endpoints)),
|
||||
)
|
||||
|
||||
return endpoints, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user