From a4e29849341a63998deb6f926f1e6db518b0009b Mon Sep 17 00:00:00 2001 From: Vladislav Veselskiy Date: Wed, 13 Mar 2024 15:24:09 +0300 Subject: [PATCH] Add logs for method DataCollection.Save. --- collection.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/collection.go b/collection.go index f8a8735..3384633 100644 --- a/collection.go +++ b/collection.go @@ -8,6 +8,7 @@ import ( "git.bit5.ru/backend/meta" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" ) type DataCollection struct { @@ -41,7 +42,10 @@ func (coll *DataCollection) Save(ctx context.Context) error { fields := coll.GetDbFields() countFields := len(fields) if countFields == 0 { - return errors.New("Fields list is empty") + err := errors.New("Fields list is empty") + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + return err } countRows := len(coll.Items) @@ -60,10 +64,21 @@ func (coll *DataCollection) Save(ctx context.Context) error { // NOTE: performance fix: if none of rows have mask we can save all data by one sql query if allDataWithoutMask { - return coll.saveWithoutMask(ctx) + if err := coll.saveWithoutMask(ctx); err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + return err + } + return nil } - return coll.saveByMask(ctx) + if err := coll.saveByMask(ctx); err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + return err + } + + return nil } func (coll *DataCollection) saveByMask(ctx context.Context) error {