add err skip
Some checks failed
automerge / automerge (pull_request) Has been skipped
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 8s
codeql / analyze (go) (pull_request) Has been cancelled
prbuild / test (pull_request) Has been cancelled
prbuild / lint (pull_request) Has been cancelled
Some checks failed
automerge / automerge (pull_request) Has been skipped
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 8s
codeql / analyze (go) (pull_request) Has been cancelled
prbuild / test (pull_request) Has been cancelled
prbuild / lint (pull_request) Has been cancelled
This commit is contained in:
parent
c363033abd
commit
cb9d32bf1c
9
.gitignore
vendored
9
.gitignore
vendored
@ -4,6 +4,7 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
bin
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
@ -13,3 +14,11 @@
|
|||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
.vscode
|
31
conn.go
31
conn.go
@ -3,6 +3,7 @@ package wrapper
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -148,7 +149,8 @@ func (w *wrapperConn) Prepare(query string) (driver.Stmt, error) {
|
|||||||
stmt, err := w.conn.Prepare(query)
|
stmt, err := w.conn.Prepare(query)
|
||||||
td := time.Since(ts)
|
td := time.Since(ts)
|
||||||
te := td.Seconds()
|
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.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
|
||||||
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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)
|
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)
|
stmt, err := conn.PrepareContext(nctx, query)
|
||||||
td := time.Since(ts)
|
td := time.Since(ts)
|
||||||
te := td.Seconds()
|
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.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
|
||||||
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
|
||||||
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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)
|
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)
|
res, err := conn.Exec(query, args)
|
||||||
td := time.Since(ts)
|
td := time.Since(ts)
|
||||||
te := td.Seconds()
|
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.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
|
||||||
} else {
|
} else {
|
||||||
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
|
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
|
||||||
}
|
}
|
||||||
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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)
|
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Exec", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel)
|
||||||
}
|
}
|
||||||
return res, err
|
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)
|
res, err := conn.ExecContext(nctx, query, args)
|
||||||
td := time.Since(ts)
|
td := time.Since(ts)
|
||||||
te := td.Seconds()
|
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.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
|
||||||
span.SetStatus(tracer.SpanStatusError, err.Error())
|
span.SetStatus(tracer.SpanStatusError, err.Error())
|
||||||
} else {
|
} 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.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
|
||||||
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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)
|
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)
|
rows, err := conn.Query(query, args)
|
||||||
td := time.Since(ts)
|
td := time.Since(ts)
|
||||||
te := td.Seconds()
|
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.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
|
||||||
} else {
|
} else {
|
||||||
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
|
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
|
||||||
}
|
}
|
||||||
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
w.opts.Meter.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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)
|
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Query", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel)
|
||||||
}
|
}
|
||||||
return rows, err
|
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)
|
rows, err := conn.QueryContext(nctx, query, args)
|
||||||
td := time.Since(ts)
|
td := time.Since(ts)
|
||||||
te := td.Seconds()
|
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.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
|
||||||
span.SetStatus(tracer.SpanStatusError, err.Error())
|
span.SetStatus(tracer.SpanStatusError, err.Error())
|
||||||
} else {
|
} 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.Summary(meterRequestLatencyMicroseconds, labels...).Update(te)
|
||||||
w.opts.Meter.Histogram(meterRequestDurationSeconds, 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)
|
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "QueryContext", getCallerName(), td, err)...).Log(ctx, w.opts.LoggerLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user