diff --git a/.gitignore b/.gitignore index 66fd13c..9e16696 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +bin # Test binary, built with `go test -c` *.test @@ -13,3 +14,11 @@ # Dependency directories (remove the comment below to include it) # vendor/ + +# Go workspace file +go.work + +# General +.DS_Store +.idea +.vscode \ No newline at end of file diff --git a/conn.go b/conn.go index f599de1..f114295 100644 --- a/conn.go +++ b/conn.go @@ -3,6 +3,7 @@ package wrapper import ( "context" "database/sql/driver" + "errors" "fmt" "time" @@ -148,7 +149,8 @@ func (w *wrapperConn) Prepare(query string) (driver.Stmt, error) { stmt, err := w.conn.Prepare(query) td := time.Since(ts) te := td.Seconds() - if err != nil { + compErr := errors.Is(err, driver.ErrSkip) + if err != nil && !compErr { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) @@ -161,7 +163,7 @@ func (w *wrapperConn) Prepare(query string) (driver.Stmt, error) { w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) - if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { + if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) && !compErr { w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Prepare", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel) } @@ -194,7 +196,8 @@ func (w *wrapperConn) PrepareContext(ctx context.Context, query string) (driver. stmt, err := conn.PrepareContext(nctx, query) td := time.Since(ts) te := td.Seconds() - if err != nil { + compErr := errors.Is(err, driver.ErrSkip) + if err != nil && !compErr { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) @@ -207,7 +210,7 @@ func (w *wrapperConn) PrepareContext(ctx context.Context, query string) (driver. w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc() w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) - if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { + if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) && !compErr { w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "PrepareContext", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel) } @@ -234,14 +237,15 @@ func (w *wrapperConn) Exec(query string, args []driver.Value) (driver.Result, er res, err := conn.Exec(query, args) td := time.Since(ts) te := td.Seconds() - if err != nil { + compErr := errors.Is(err, driver.ErrSkip) + if err != nil && !compErr { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() } else { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc() } w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) - if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { + if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) && !compErr { w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Exec", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel) } return res, err @@ -279,7 +283,8 @@ func (w *wrapperConn) ExecContext(ctx context.Context, query string, args []driv res, err := conn.ExecContext(nctx, query, args) td := time.Since(ts) te := td.Seconds() - if err != nil { + compErr := errors.Is(err, driver.ErrSkip) + if err != nil && !compErr { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() span.SetStatus(tracer.SpanStatusError, err.Error()) } else { @@ -288,7 +293,7 @@ func (w *wrapperConn) ExecContext(ctx context.Context, query string, args []driv w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc() w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) - if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { + if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) && !compErr { w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "ExecContext", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel) } @@ -356,14 +361,15 @@ func (w *wrapperConn) Query(query string, args []driver.Value) (driver.Rows, err rows, err := conn.Query(query, args) td := time.Since(ts) te := td.Seconds() - if err != nil { + compErr := errors.Is(err, driver.ErrSkip) + if err != nil && !compErr { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() } else { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc() } w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) - if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { + if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) && !compErr { w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Query", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel) } return rows, err @@ -399,7 +405,8 @@ func (w *wrapperConn) QueryContext(ctx context.Context, query string, args []dri rows, err := conn.QueryContext(nctx, query, args) td := time.Since(ts) te := td.Seconds() - if err != nil { + compErr := errors.Is(err, driver.ErrSkip) + if err != nil && !compErr { w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() span.SetStatus(tracer.SpanStatusError, err.Error()) } else { @@ -407,7 +414,7 @@ func (w *wrapperConn) QueryContext(ctx context.Context, query string, args []dri } w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te) w.opts.Meter.Histogram(meterRequestDurationSeconds, labels...).Update(te) - if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { + if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) && !compErr { w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "QueryContext", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel) }