From 95860fc561f04e5d5ab9c41ffa95073ed1961b70 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 16 Jan 2023 15:19:30 +0300 Subject: [PATCH] small fixes for span logs Signed-off-by: Vasiliy Tolstov --- tx.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tx.go b/tx.go index 7aae403..01defaf 100644 --- a/tx.go +++ b/tx.go @@ -24,6 +24,11 @@ func (w *wrapperTx) Commit() error { err := w.tx.Commit() td := time.Since(ts) + if err != nil { + w.span.AddLabels("error", true) + w.span.AddLabels("err", err.Error()) + } + if w.opts.LoggerEnabled { w.opts.Logger.Fields(w.opts.LoggerObserver(context.TODO(), "Commit", labelUnknown, td, err)...).Log(context.TODO(), w.opts.LoggerLevel) } @@ -40,6 +45,11 @@ func (w *wrapperTx) Rollback() error { err := w.tx.Rollback() td := time.Since(ts) + if err != nil { + w.span.AddLabels("error", true) + w.span.AddLabels("err", err.Error()) + } + if w.opts.LoggerEnabled { w.opts.Logger.Fields(w.opts.LoggerObserver(context.TODO(), "Rollback", labelUnknown, td, err)...).Log(context.TODO(), w.opts.LoggerLevel) }