Compare commits

..

14 Commits
v3.10.4 ... v3

Author SHA1 Message Date
3b6167f7da update for latest micro logger changes
Some checks failed
codeql / analyze (go) (push) Failing after 41s
build / test (push) Failing after 4m54s
build / lint (push) Successful in 9m29s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-10-14 15:22:14 +03:00
7ac873c62f update deps, minimise memory allocations
Some checks failed
build / test (push) Failing after 8s
build / lint (push) Failing after 7s
codeql / analyze (go) (push) Failing after 10s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-09-20 18:17:16 +03:00
44256cd62f fixup tracing
Some checks failed
build / test (push) Failing after 1m49s
codeql / analyze (go) (push) Failing after 1m43s
build / lint (push) Successful in 9m16s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-05-06 08:56:16 +03:00
0dfee57dd4 fixup tracing
Some checks failed
codeql / analyze (go) (push) Failing after 1m41s
build / test (push) Failing after 1m46s
build / lint (push) Successful in 9m18s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-14 23:24:44 +03:00
6499c64759 update for latest logger changes
Some checks failed
codeql / analyze (go) (push) Failing after 1m48s
build / lint (push) Successful in 16m41s
build / test (push) Failing after 23m4s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-11 02:04:15 +03:00
87785d978a update for latest micro and requestid changes
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-11 01:55:55 +03:00
df45b9e0bb fix label names
Some checks failed
build / test (push) Failing after 1m28s
build / lint (push) Failing after 2m40s
codeql / analyze (go) (push) Failing after 3m8s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-09-05 07:08:53 +03:00
b31e3e7ffa Merge pull request 'tracing updates' (#79) from updates into v3
Some checks failed
build / test (push) Failing after 1m28s
build / lint (push) Failing after 2m44s
codeql / analyze (go) (push) Failing after 3m20s
Reviewed-on: #79
2023-09-01 14:40:50 +03:00
0e8e4d6e55 Merge branch 'v3' into updates
Some checks failed
autoapprove / autoapprove (pull_request) Failing after 1m25s
automerge / automerge (pull_request) Failing after 5s
codeql / analyze (go) (pull_request) Failing after 3m11s
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m28s
prbuild / lint (pull_request) Failing after 2m43s
2023-09-01 14:40:36 +03:00
34c80e29bc tracing updates
Some checks failed
autoapprove / autoapprove (pull_request) Failing after 1m26s
automerge / automerge (pull_request) Failing after 4s
codeql / analyze (go) (pull_request) Failing after 3m11s
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m29s
prbuild / lint (pull_request) Failing after 2m33s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-09-01 14:32:27 +03:00
974a911bfa Обновить go.mod
Some checks failed
build / test (push) Failing after 1m27s
build / lint (push) Failing after 2m34s
codeql / analyze (go) (push) Failing after 3m11s
2023-09-01 00:26:30 +03:00
cde783029d Merge pull request 'fixup metrics and tracing' (#78) from fixup into v3
Some checks failed
build / test (push) Failing after 1m27s
build / lint (push) Failing after 2m29s
codeql / analyze (go) (push) Failing after 3m3s
Reviewed-on: #78
2023-09-01 00:21:58 +03:00
927218921e fixup metrics and tracing
Some checks failed
autoapprove / autoapprove (pull_request) Failing after 1m26s
automerge / automerge (pull_request) Failing after 4s
codeql / analyze (go) (pull_request) Failing after 3m16s
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m29s
prbuild / lint (pull_request) Failing after 2m36s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-09-01 00:21:08 +03:00
4b3ba3f76a fixup v3
Some checks failed
build / test (push) Failing after 1m28s
build / lint (push) Failing after 2m41s
codeql / analyze (go) (push) Failing after 2m31s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-29 01:30:27 +03:00
11 changed files with 2432 additions and 2350 deletions

View File

@ -4,6 +4,7 @@ import (
"database/sql/driver" "database/sql/driver"
"errors" "errors"
"fmt" "fmt"
"runtime"
) )
//go:generate sh -c "go run gen.go > wrap_gen.go" //go:generate sh -c "go run gen.go > wrap_gen.go"
@ -31,7 +32,20 @@ func namedValueToLabels(named []driver.NamedValue) []interface{} {
} else { } else {
name = fmt.Sprintf("$%d", param.Ordinal) name = fmt.Sprintf("$%d", param.Ordinal)
} }
largs = append(largs, fmt.Sprintf("%s=%s", name, param.Value)) largs = append(largs, fmt.Sprintf("%s=%v", name, param.Value))
} }
return largs return largs
} }
// getCallerName get the name of the function A where A() -> B() -> GetFunctionCallerName()
func getCallerName() string {
pc, _, _, ok := runtime.Caller(3)
details := runtime.FuncForPC(pc)
var callerName string
if ok && details != nil {
callerName = details.Name()
} else {
callerName = labelUnknown
}
return callerName
}

181
conn.go
View File

@ -6,7 +6,8 @@ import (
"fmt" "fmt"
"time" "time"
"go.unistack.org/micro/v4/tracer" requestid "go.unistack.org/micro-wrapper-requestid/v3"
"go.unistack.org/micro/v3/tracer"
) )
var ( var (
@ -15,9 +16,9 @@ var (
_ driver.ConnPrepareContext = (*wrapperConn)(nil) _ driver.ConnPrepareContext = (*wrapperConn)(nil)
_ driver.Pinger = (*wrapperConn)(nil) _ driver.Pinger = (*wrapperConn)(nil)
_ driver.Validator = (*wrapperConn)(nil) _ driver.Validator = (*wrapperConn)(nil)
_ driver.Queryer = (*wrapperConn)(nil) _ driver.Queryer = (*wrapperConn)(nil) // nolint:staticcheck
_ driver.QueryerContext = (*wrapperConn)(nil) _ driver.QueryerContext = (*wrapperConn)(nil)
_ driver.Execer = (*wrapperConn)(nil) _ driver.Execer = (*wrapperConn)(nil) // nolint:staticcheck
_ driver.ExecerContext = (*wrapperConn)(nil) _ driver.ExecerContext = (*wrapperConn)(nil)
// _ driver.Connector // _ driver.Connector
// _ driver.Driver // _ driver.Driver
@ -42,7 +43,7 @@ func (w *wrapperConn) Close() error {
} else { } else {
ctx = context.Background() ctx = context.Background()
} }
_ = ctx
labels := []string{labelMethod, "Close"} labels := []string{labelMethod, "Close"}
ts := time.Now() ts := time.Now()
err := w.conn.Close() err := w.conn.Close()
@ -55,11 +56,11 @@ func (w *wrapperConn) Close() 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Close", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Close", getCallerName(), td, err)...)
} }
*/
return err return err
} }
@ -81,30 +82,32 @@ func (w *wrapperConn) Begin() (driver.Tx, error) {
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)
/*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Begin", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Begin", getCallerName(), td, err)...)
} }
*/
return nil, err return nil, err
} }
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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Begin", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Begin", getCallerName(), td, err)...)
} }
*/
return &wrapperTx{tx: tx, opts: w.opts, ctx: ctx}, nil return &wrapperTx{tx: tx, opts: w.opts, ctx: ctx}, nil
} }
// BeginTx implements driver.ConnBeginTx BeginTx // BeginTx implements driver.ConnBeginTx BeginTx
func (w *wrapperConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { func (w *wrapperConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
nctx, span := w.opts.Tracer.Start(ctx, "Transaction")
span.AddLabels("method", "BeginTx")
name := getQueryName(ctx) name := getQueryName(ctx)
if name != "" { nctx, span := w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
span.AddLabels("query", name) span.AddLabels("db.method", "BeginTx")
} else { span.AddLabels("db.statement", name)
name = labelUnknown if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id)
} }
labels := []string{labelMethod, "BeginTx", labelQuery, name} labels := []string{labelMethod, "BeginTx", labelQuery, name}
@ -121,17 +124,20 @@ func (w *wrapperConn) BeginTx(ctx context.Context, opts driver.TxOptions) (drive
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)
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error()) /*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "BeginTx", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "BeginTx", getCallerName(), td, err)...)
} }
*/
return nil, err return nil, err
} }
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
/*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "BeginTx", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "BeginTx", getCallerName(), td, err)...)
} }
*/
return &wrapperTx{tx: tx, opts: w.opts, ctx: ctx, span: span}, nil return &wrapperTx{tx: tx, opts: w.opts, ctx: ctx, span: span}, nil
} }
@ -143,8 +149,8 @@ func (w *wrapperConn) Prepare(query string) (driver.Stmt, error) {
} else { } else {
ctx = context.Background() ctx = context.Background()
} }
_ = ctx
labels := []string{labelMethod, "Prepare", labelQuery, labelUnknown} labels := []string{labelMethod, "Prepare", labelQuery, getCallerName()}
ts := time.Now() ts := time.Now()
stmt, err := w.conn.Prepare(query) stmt, err := w.conn.Prepare(query)
td := time.Since(ts) td := time.Since(ts)
@ -153,20 +159,21 @@ func (w *wrapperConn) Prepare(query string) (driver.Stmt, error) {
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)
/*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Prepare", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Prepare", getCallerName(), td, err)...)
} }
*/
return nil, err return nil, err
} }
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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Prepare", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Prepare", getCallerName(), td, err)...)
} }
*/
return wrapStmt(stmt, query, w.opts), nil return wrapStmt(stmt, query, w.opts), nil
} }
@ -174,19 +181,18 @@ func (w *wrapperConn) Prepare(query string) (driver.Stmt, error) {
func (w *wrapperConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { func (w *wrapperConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "PrepareContext")
} else {
nctx, span = w.opts.Tracer.Start(ctx, "PrepareContext")
}
span.AddLabels("method", "PrepareContext")
name := getQueryName(ctx)
if name != "" {
span.AddLabels("query", name)
} else {
name = labelUnknown
}
name := getQueryName(ctx)
if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} else {
nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
}
span.AddLabels("db.method", "PrepareContext")
span.AddLabels("db.statement", name)
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id)
}
labels := []string{labelMethod, "PrepareContext", labelQuery, name} labels := []string{labelMethod, "PrepareContext", labelQuery, name}
conn, ok := w.conn.(driver.ConnPrepareContext) conn, ok := w.conn.(driver.ConnPrepareContext)
if !ok { if !ok {
@ -201,20 +207,22 @@ func (w *wrapperConn) PrepareContext(ctx context.Context, query string) (driver.
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)
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error()) /*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "PrepareContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "PrepareContext", getCallerName(), td, err)...)
} }
*/
return nil, err return nil, err
} }
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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "PrepareContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "PrepareContext", getCallerName(), td, err)...)
} }
*/
return wrapStmt(stmt, query, w.opts), nil return wrapStmt(stmt, query, w.opts), nil
} }
@ -226,7 +234,8 @@ func (w *wrapperConn) Exec(query string, args []driver.Value) (driver.Result, er
} else { } else {
ctx = context.Background() ctx = context.Background()
} }
labels := []string{labelMethod, "Exec", labelQuery, labelUnknown} _ = ctx
labels := []string{labelMethod, "Exec", labelQuery, getCallerName()}
// nolint:staticcheck // nolint:staticcheck
conn, ok := w.conn.(driver.Execer) conn, ok := w.conn.(driver.Execer)
@ -245,9 +254,11 @@ func (w *wrapperConn) Exec(query string, args []driver.Value) (driver.Result, er
} }
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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Exec", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Exec", getCallerName(), td, err)...)
} }
*/
return res, err return res, err
} }
@ -256,24 +267,22 @@ func (w *wrapperConn) ExecContext(ctx context.Context, query string, args []driv
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "ExecContext")
} else {
nctx, span = w.opts.Tracer.Start(ctx, "ExecContext")
}
span.AddLabels("method", "ExecContext")
name := getQueryName(ctx) name := getQueryName(ctx)
if name != "" { if w.ctx != nil {
span.AddLabels("query", name) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
name = labelUnknown nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
}
span.AddLabels("db.method", "ExecContext")
span.AddLabels("db.statement", name)
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id)
} }
defer span.Finish() defer span.Finish()
if len(args) > 0 { if len(args) > 0 {
span.AddLabels("args", fmt.Sprintf("%v", namedValueToLabels(args))) span.AddLabels("db.args", fmt.Sprintf("%v", namedValueToLabels(args)))
} }
labels := []string{labelMethod, "ExecContext", labelQuery, name} labels := []string{labelMethod, "ExecContext", labelQuery, name}
fmt.Printf("EXECCONTETX args %#+v\n", args)
conn, ok := w.conn.(driver.ExecerContext) conn, ok := w.conn.(driver.ExecerContext)
if !ok { if !ok {
@ -287,18 +296,18 @@ func (w *wrapperConn) ExecContext(ctx context.Context, query string, args []driv
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error())
} 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.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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "ExecContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "ExecContext", getCallerName(), td, err)...)
} }
*/
return res, err return res, err
} }
@ -316,13 +325,17 @@ func (w *wrapperConn) Ping(ctx context.Context) error {
} }
var nctx context.Context var nctx context.Context
nctx = ctx
/*
var span tracer.Span var span tracer.Span
if w.ctx != nil { if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "Ping") nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
nctx, span = w.opts.Tracer.Start(ctx, "Ping") nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "Ping")
defer span.Finish() defer span.Finish()
*/
labels := []string{labelMethod, "Ping"} labels := []string{labelMethod, "Ping"}
ts := time.Now() ts := time.Now()
err := conn.Ping(nctx) err := conn.Ping(nctx)
@ -330,11 +343,12 @@ func (w *wrapperConn) Ping(ctx context.Context) error {
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) // span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error()) /*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Ping", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Ping", getCallerName(), td, err)...)
} }
*/
return err return err
} else { } else {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelSuccess)...).Inc()
@ -353,13 +367,14 @@ func (w *wrapperConn) Query(query string, args []driver.Value) (driver.Rows, err
} else { } else {
ctx = context.Background() ctx = context.Background()
} }
_ = ctx
// nolint:staticcheck // nolint:staticcheck
conn, ok := w.conn.(driver.Queryer) conn, ok := w.conn.(driver.Queryer)
if !ok { if !ok {
return nil, driver.ErrSkip return nil, driver.ErrSkip
} }
labels := []string{labelMethod, "Query", labelQuery, labelUnknown} labels := []string{labelMethod, "Query", labelQuery, getCallerName()}
ts := time.Now() ts := time.Now()
rows, err := conn.Query(query, args) rows, err := conn.Query(query, args)
td := time.Since(ts) td := time.Since(ts)
@ -371,9 +386,11 @@ func (w *wrapperConn) Query(query string, args []driver.Value) (driver.Rows, err
} }
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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Query", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Query", getCallerName(), td, err)...)
} }
*/
return rows, err return rows, err
} }
@ -381,21 +398,21 @@ func (w *wrapperConn) Query(query string, args []driver.Value) (driver.Rows, err
func (w *wrapperConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { func (w *wrapperConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "QueryContext")
} else {
nctx, span = w.opts.Tracer.Start(ctx, "QueryContext")
}
span.AddLabels("method", "QueryContext")
name := getQueryName(ctx) name := getQueryName(ctx)
if name != "" { if w.ctx != nil {
span.AddLabels("query", name) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
name = labelUnknown nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
}
span.AddLabels("db.method", "QueryContext")
span.AddLabels("db.statement", name)
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id)
} }
defer span.Finish() defer span.Finish()
if len(args) > 0 { if len(args) > 0 {
span.AddLabels("args", fmt.Sprintf("%v", namedValueToLabels(args))) span.AddLabels("db.args", fmt.Sprintf("%v", namedValueToLabels(args)))
} }
labels := []string{labelMethod, "QueryContext", labelQuery, name} labels := []string{labelMethod, "QueryContext", labelQuery, name}
conn, ok := w.conn.(driver.QueryerContext) conn, ok := w.conn.(driver.QueryerContext)
@ -409,17 +426,17 @@ func (w *wrapperConn) QueryContext(ctx context.Context, query string, args []dri
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error())
} 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "QueryContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "QueryContext", getCallerName(), td, err)...)
} }
*/
return rows, err return rows, err
} }

View File

@ -25,33 +25,35 @@ type conn interface {
// wrapperDriver defines a wrapper for driver.Driver // wrapperDriver defines a wrapper for driver.Driver
type wrapperDriver struct { type wrapperDriver struct {
driver driver.Driver driver driver.Driver
connector driver.Connector
opts Options opts Options
ctx context.Context ctx context.Context
} }
type wrapperConnector struct {
driver driver.Driver
name string
opts Options
}
// NewWrapper creates and returns a new SQL driver with passed capabilities // NewWrapper creates and returns a new SQL driver with passed capabilities
func NewWrapper(d driver.Driver, opts ...Option) driver.Driver { func NewWrapper(d driver.Driver, opts ...Option) driver.Driver {
return &wrapperDriver{driver: d, opts: NewOptions(opts...), ctx: context.Background()} return &wrapperDriver{driver: d, opts: NewOptions(opts...), ctx: context.Background()}
} }
/* type wrappedConnector struct {
connector driver.Connector
name string
opts Options
ctx context.Context
}
func NewWrapperConnector(c driver.Connector, opts ...Option) driver.Connector {
return &wrappedConnector{connector: c, opts: NewOptions(opts...), ctx: context.Background()}
}
// Connect implements driver.Driver Connect // Connect implements driver.Driver Connect
func (w *wrapperConnector) Connect(ctx context.Context) (driver.Conn, error) { func (w *wrappedConnector) Connect(ctx context.Context) (driver.Conn, error) {
return w.driver.Connect(ctx) return w.connector.Connect(ctx)
} }
// Driver implements driver.Driver Driver // Driver implements driver.Driver Driver
func (w *wrapperConnector) Driver() driver.Driver { func (w *wrappedConnector) Driver() driver.Driver {
return w.driver return w.connector.Driver()
} }
*/
/* /*
// Connect implements driver.Driver OpenConnector // Connect implements driver.Driver OpenConnector
@ -76,10 +78,12 @@ func (w *wrapperDriver) Open(name string) (driver.Conn, error) {
ts := time.Now() ts := time.Now()
c, err := w.driver.Open(name) c, err := w.driver.Open(name)
td := time.Since(ts) td := time.Since(ts)
/*
if w.opts.LoggerEnabled { if w.opts.LoggerEnabled {
w.opts.Logger.Fields(w.opts.LoggerObserver(w.ctx, "Open", labelUnknown, td, err)...).Log(w.ctx, w.opts.LoggerLevel) w.opts.Logger.Log(w.ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(w.ctx, "Open", getCallerName(), td, err)...)
} }
*/
_ = td
if err != nil { if err != nil {
return nil, err return nil, err
} }

16
gen.go
View File

@ -66,7 +66,7 @@ func main() {
continue continue
} }
h := getHash(ifaces) h := getHash(ifaces)
b.WriteString(fmt.Sprintf("\tif v, ok := dc.(wrapConn%04d_%s); ok {\n", n, h)) b.WriteString(fmt.Sprintf("\tif _, ok := dc.(wrapConn%04d_%s); ok {\n", n, h))
b.WriteString("\treturn struct {\n") b.WriteString("\treturn struct {\n")
b.WriteString("\t\tdriver.Conn\n") b.WriteString("\t\tdriver.Conn\n")
b.WriteString(fmt.Sprintf("\t\t\t%s", strings.Join(ifaces, "\n\t\t\t"))) b.WriteString(fmt.Sprintf("\t\t\t%s", strings.Join(ifaces, "\n\t\t\t")))
@ -74,14 +74,14 @@ func main() {
for idx := range ifaces { for idx := range ifaces {
if idx > 0 { if idx > 0 {
b.WriteString(", ") b.WriteString(", ")
b.WriteString("v") b.WriteString("c")
} else if idx == 0 { } else if idx == 0 {
b.WriteString("c") b.WriteString("c")
} else { } else {
b.WriteString("v") b.WriteString("c")
} }
} }
b.WriteString(", v}\n") b.WriteString(", c}\n")
b.WriteString("}\n\n") b.WriteString("}\n\n")
} }
b.WriteString("return c\n") b.WriteString("return c\n")
@ -112,7 +112,7 @@ func main() {
continue continue
} }
h := getHash(ifaces) h := getHash(ifaces)
b.WriteString(fmt.Sprintf("\tif v, ok := stmt.(wrapStmt%04d_%s); ok {\n", n, h)) b.WriteString(fmt.Sprintf("\tif _, ok := stmt.(wrapStmt%04d_%s); ok {\n", n, h))
b.WriteString("\treturn struct {\n") b.WriteString("\treturn struct {\n")
b.WriteString("\t\tdriver.Stmt\n") b.WriteString("\t\tdriver.Stmt\n")
b.WriteString(fmt.Sprintf("\t\t\t%s", strings.Join(ifaces, "\n\t\t\t"))) b.WriteString(fmt.Sprintf("\t\t\t%s", strings.Join(ifaces, "\n\t\t\t")))
@ -120,14 +120,14 @@ func main() {
for idx := range ifaces { for idx := range ifaces {
if idx > 0 { if idx > 0 {
b.WriteString(", ") b.WriteString(", ")
b.WriteString("v") b.WriteString("c")
} else if idx == 0 { } else if idx == 0 {
b.WriteString("c") b.WriteString("c")
} else { } else {
b.WriteString("v") b.WriteString("c")
} }
} }
b.WriteString(", v}\n") b.WriteString(", c}\n")
b.WriteString("}\n\n") b.WriteString("}\n\n")
} }
b.WriteString("return c\n") b.WriteString("return c\n")

19
go.mod
View File

@ -1,5 +1,18 @@
module go.unistack.org/micro-wrapper-sql/v4 module go.unistack.org/micro-wrapper-sql/v3
go 1.19 go 1.22
require go.unistack.org/micro/v4 v4.0.3 toolchain go1.23.2
require (
go.unistack.org/micro-wrapper-requestid/v3 v3.9.2
go.unistack.org/micro/v3 v3.10.97
)
require (
go.unistack.org/micro-proto/v3 v3.4.1 // indirect
golang.org/x/sys v0.26.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
)

41
go.sum
View File

@ -1,2 +1,39 @@
go.unistack.org/micro/v4 v4.0.3 h1:AFr21ua3IrkuxH26kNYVrs7Kpsrm+4aylE/PfjLdCWM= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
go.unistack.org/micro/v4 v4.0.3/go.mod h1:+wBa98rSf+mRXb/MuSVFPXtDrqN0k8rzPQiC8wRCwCo= go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
go.unistack.org/micro-wrapper-requestid/v3 v3.8.10 h1:9QZy6w1HU2RCppZ1t8wJsDg1pk9RbvzUFYurq3Ai29Y=
go.unistack.org/micro-wrapper-requestid/v3 v3.8.10/go.mod h1:3tY5+DwQM7l07chnpu/Wzwnne/ZV75VsUwXR54/WYzo=
go.unistack.org/micro-wrapper-requestid/v3 v3.9.2 h1:Wu0oIGJieH37xroCjlaPivuqTGmv5l5KWgVaRQWEQMY=
go.unistack.org/micro-wrapper-requestid/v3 v3.9.2/go.mod h1:cqgjdSSASTnOLjvwndP9bi0b8DbuoKbDII884R5puwU=
go.unistack.org/micro/v3 v3.10.57 h1:VxG7Cs7kBOgxgQlP+K8TvTxIgh2pmqAwmAaKdTAQNtQ=
go.unistack.org/micro/v3 v3.10.57/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
go.unistack.org/micro/v3 v3.10.91 h1:vuJY4tXwpqimwIkEJ3TozMYNVQQs+C5QMlQWPgSY/YM=
go.unistack.org/micro/v3 v3.10.91/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
go.unistack.org/micro/v3 v3.10.97 h1:8l7fv+i06/PjPrBBhRC/ZQkWGIOuHPg3jJN0vktYE78=
go.unistack.org/micro/v3 v3.10.97/go.mod h1:YzMldzHN9Ei+zy5t/Psu7RUWDZwUfrNYiStSQtTz90g=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw=
google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=

View File

@ -5,19 +5,17 @@ import (
"fmt" "fmt"
"time" "time"
"go.unistack.org/micro/v4/logger" "go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v4/meter" "go.unistack.org/micro/v3/meter"
"go.unistack.org/micro/v4/tracer" "go.unistack.org/micro/v3/tracer"
) )
var ( var (
// DefaultMeterStatsInterval holds default stats interval // DefaultMeterStatsInterval holds default stats interval
DefaultMeterStatsInterval = 5 * time.Second DefaultMeterStatsInterval = 5 * time.Second
// DefaultMeterMetricPrefix holds default metric prefix
DefaultMeterMetricPrefix = "micro_sql_"
// DefaultLoggerObserver used to prepare labels for logger // DefaultLoggerObserver used to prepare labels for logger
DefaultLoggerObserver = func(ctx context.Context, method string, query string, td time.Duration, err error) []interface{} { DefaultLoggerObserver = func(ctx context.Context, method string, query string, td time.Duration, err error) []interface{} {
labels := []interface{}{"method", method, "took", fmt.Sprintf("%v", td)} labels := []interface{}{"db.method", method, "took", fmt.Sprintf("%v", td)}
if err != nil { if err != nil {
labels = append(labels, "error", err.Error()) labels = append(labels, "error", err.Error())
} }
@ -29,23 +27,23 @@ var (
) )
var ( var (
MaxOpenConnections = "max_open_connections" MaxOpenConnections = "micro_sql_max_open_conn"
OpenConnections = "open_connections" OpenConnections = "micro_sql_open_conn"
InuseConnections = "inuse_connections" InuseConnections = "micro_sql_inuse_conn"
IdleConnections = "idle_connections" IdleConnections = "micro_sql_idle_conn"
WaitConnections = "wait_connections" WaitConnections = "micro_sql_waited_conn"
BlockedSeconds = "blocked_seconds" BlockedSeconds = "micro_sql_blocked_seconds"
MaxIdleClosed = "max_idle_closed" MaxIdleClosed = "micro_sql_max_idle_closed"
MaxIdletimeClosed = "max_idletime_closed" MaxIdletimeClosed = "micro_sql_closed_max_idle"
MaxLifetimeClosed = "max_lifetime_closed" MaxLifetimeClosed = "micro_sql_closed_max_lifetime"
meterRequestTotal = "request_total" meterRequestTotal = "micro_sql_request_total"
meterRequestLatencyMicroseconds = "request_latency_microseconds" meterRequestLatencyMicroseconds = "micro_sql_latency_microseconds"
meterRequestDurationSeconds = "request_duration_seconds" meterRequestDurationSeconds = "micro_sql_request_duration_seconds"
labelUnknown = "unknown" labelUnknown = "unknown"
labelQuery = "query" labelQuery = "db_statement"
labelMethod = "method" labelMethod = "db_method"
labelStatus = "status" labelStatus = "status"
labelSuccess = "success" labelSuccess = "success"
labelFailure = "failure" labelFailure = "failure"
@ -60,7 +58,6 @@ type Options struct {
Tracer tracer.Tracer Tracer tracer.Tracer
DatabaseHost string DatabaseHost string
DatabaseName string DatabaseName string
MeterMetricPrefix string
MeterStatsInterval time.Duration MeterStatsInterval time.Duration
LoggerLevel logger.Level LoggerLevel logger.Level
LoggerEnabled bool LoggerEnabled bool
@ -77,8 +74,7 @@ func NewOptions(opts ...Option) Options {
Meter: meter.DefaultMeter, Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer, Tracer: tracer.DefaultTracer,
MeterStatsInterval: DefaultMeterStatsInterval, MeterStatsInterval: DefaultMeterStatsInterval,
MeterMetricPrefix: DefaultMeterMetricPrefix, LoggerLevel: logger.ErrorLevel,
LoggerLevel: logger.DebugLevel,
LoggerObserver: DefaultLoggerObserver, LoggerObserver: DefaultLoggerObserver,
} }
for _, o := range opts { for _, o := range opts {
@ -86,14 +82,13 @@ func NewOptions(opts ...Option) Options {
} }
options.Meter = options.Meter.Clone( options.Meter = options.Meter.Clone(
meter.MetricPrefix(options.MeterMetricPrefix),
meter.Labels( meter.Labels(
labelHost, options.DatabaseHost, labelHost, options.DatabaseHost,
labelDatabase, options.DatabaseName, labelDatabase, options.DatabaseName,
), ),
) )
options.Logger = options.Logger.Clone(logger.WithCallerSkipCount(1)) options.Logger = options.Logger.Clone(logger.WithAddCallerSkipCount(1))
return options return options
} }
@ -105,13 +100,6 @@ func MetricInterval(td time.Duration) Option {
} }
} }
// MetricPrefix specifies prefix for each metric
func MetricPrefix(pref string) Option {
return func(o *Options) {
o.MeterMetricPrefix = pref
}
}
func DatabaseHost(host string) Option { func DatabaseHost(host string) Option {
return func(o *Options) { return func(o *Options) {
o.DatabaseHost = host o.DatabaseHost = host
@ -177,8 +165,8 @@ func QueryName(ctx context.Context, name string) context.Context {
} }
func getQueryName(ctx context.Context) string { func getQueryName(ctx context.Context) string {
if v, ok := ctx.Value(queryNameKey{}).(string); ok { if v, ok := ctx.Value(queryNameKey{}).(string); ok && v != labelUnknown {
return v return v
} }
return "" return getCallerName()
} }

View File

@ -1,4 +1,4 @@
package wrapper // import "go.unistack.org/micro-wrapper-sql-1/v3" package wrapper // import "go.unistack.org/micro-wrapper-sql/v3"
import ( import (
"context" "context"

125
stmt.go
View File

@ -6,7 +6,8 @@ import (
"fmt" "fmt"
"time" "time"
"go.unistack.org/micro/v4/tracer" requestid "go.unistack.org/micro-wrapper-requestid/v3"
"go.unistack.org/micro/v3/tracer"
) )
var ( var (
@ -32,6 +33,7 @@ func (w *wrapperStmt) Close() error {
} else { } else {
ctx = context.Background() ctx = context.Background()
} }
_ = ctx
labels := []string{labelMethod, "Close"} labels := []string{labelMethod, "Close"}
ts := time.Now() ts := time.Now()
err := w.stmt.Close() err := w.stmt.Close()
@ -44,10 +46,11 @@ func (w *wrapperStmt) Close() 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Close", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Close", getCallerName(), td, err)...)
} }
*/
return err return err
} }
@ -73,6 +76,7 @@ func (w *wrapperStmt) Exec(args []driver.Value) (driver.Result, error) {
} else { } else {
ctx = context.Background() ctx = context.Background()
} }
_ = ctx
labels := []string{labelMethod, "Exec"} labels := []string{labelMethod, "Exec"}
ts := time.Now() ts := time.Now()
res, err := w.stmt.Exec(args) // nolint:staticcheck res, err := w.stmt.Exec(args) // nolint:staticcheck
@ -85,11 +89,11 @@ func (w *wrapperStmt) Exec(args []driver.Value) (driver.Result, 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Exec", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Exec", getCallerName(), td, err)...)
} }
*/
return res, err return res, err
} }
@ -101,10 +105,10 @@ func (w *wrapperStmt) Query(args []driver.Value) (driver.Rows, error) {
} else { } else {
ctx = context.Background() ctx = context.Background()
} }
_ = ctx
labels := []string{labelMethod, "Query"} labels := []string{labelMethod, "Query"}
ts := time.Now() ts := time.Now()
// nolint:staticcheck rows, err := w.stmt.Query(args) // nolint:staticcheck
rows, err := w.stmt.Query(args)
td := time.Since(ts) td := time.Since(ts)
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
@ -114,33 +118,42 @@ func (w *wrapperStmt) Query(args []driver.Value) (driver.Rows, 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Query", labelUnknown, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "Query", getCallerName(), td, err)...)
} }
*/
return rows, err return rows, err
} }
// ColumnConverter implements driver.ColumnConverter
func (w *wrapperStmt) ColumnConverter(idx int) driver.ValueConverter {
s, ok := w.stmt.(driver.ColumnConverter) // nolint:staticcheck
if !ok {
return nil
}
return s.ColumnConverter(idx)
}
// ExecContext implements driver.StmtExecContext ExecContext // ExecContext implements driver.StmtExecContext ExecContext
func (w *wrapperStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { func (w *wrapperStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "ExecContext")
} else {
nctx, span = w.opts.Tracer.Start(ctx, "ExecContext")
}
span.AddLabels("method", "ExecContext")
name := getQueryName(ctx) name := getQueryName(ctx)
if name != "" { if w.ctx != nil {
span.AddLabels("query", name) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
name = labelUnknown nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "ExecContext")
span.AddLabels("db.statement", name)
defer span.Finish() defer span.Finish()
if len(args) > 0 { if len(args) > 0 {
span.AddLabels("args", fmt.Sprintf("%v", namedValueToLabels(args))) span.AddLabels("db.args", fmt.Sprintf("%v", namedValueToLabels(args)))
}
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id)
} }
labels := []string{labelMethod, "ExecContext", labelQuery, name} labels := []string{labelMethod, "ExecContext", labelQuery, name}
@ -151,29 +164,29 @@ func (w *wrapperStmt) ExecContext(ctx context.Context, args []driver.NamedValue)
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error())
} 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "ExecContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "ExecContext", name, td, err)...)
} }
*/
return res, err return res, err
} }
values, err := namedValueToValue(args) values, err := namedValueToValue(args)
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error()) /*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "ExecContext", name, 0, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "ExecContext", name, 0, err)...)
} }
*/
return nil, err return nil, err
} }
ts := time.Now() ts := time.Now()
@ -182,19 +195,18 @@ func (w *wrapperStmt) ExecContext(ctx context.Context, args []driver.NamedValue)
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error())
} 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "ExecContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "ExecContext", name, td, err)...)
} }
*/
return res, err return res, err
} }
@ -202,21 +214,21 @@ func (w *wrapperStmt) ExecContext(ctx context.Context, args []driver.NamedValue)
func (w *wrapperStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { func (w *wrapperStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "QueryContext")
} else {
nctx, span = w.opts.Tracer.Start(ctx, "QueryContext")
}
span.AddLabels("method", "QueryContext")
name := getQueryName(ctx) name := getQueryName(ctx)
if name != "" { if w.ctx != nil {
span.AddLabels("query", name) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
name = labelUnknown nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "QueryContext")
span.AddLabels("db.statement", name)
defer span.Finish() defer span.Finish()
if len(args) > 0 { if len(args) > 0 {
span.AddLabels("args", fmt.Sprintf("%v", namedValueToLabels(args))) span.AddLabels("db.args", fmt.Sprintf("%v", namedValueToLabels(args)))
}
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id)
} }
labels := []string{labelMethod, "QueryContext", labelQuery, name} labels := []string{labelMethod, "QueryContext", labelQuery, name}
if conn, ok := w.stmt.(driver.StmtQueryContext); ok { if conn, ok := w.stmt.(driver.StmtQueryContext); ok {
@ -226,18 +238,18 @@ func (w *wrapperStmt) QueryContext(ctx context.Context, args []driver.NamedValue
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error())
} 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "QueryContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "QueryContext", name, td, err)...)
} }
*/
return rows, err return rows, err
} }
@ -245,12 +257,12 @@ func (w *wrapperStmt) QueryContext(ctx context.Context, args []driver.NamedValue
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error()) /*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "QueryContext", name, 0, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "QueryContext", name, 0, err)...)
} }
*/
return nil, err return nil, err
} }
ts := time.Now() ts := time.Now()
@ -259,18 +271,17 @@ func (w *wrapperStmt) QueryContext(ctx context.Context, args []driver.NamedValue
te := td.Seconds() te := td.Seconds()
if err != nil { if err != nil {
w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc() w.opts.Meter.Counter(meterRequestTotal, append(labels, labelStatus, labelFailure)...).Inc()
span.AddLabels("error", true) span.SetStatus(tracer.SpanStatusError, err.Error())
span.AddLabels("err", err.Error())
} 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) {
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "QueryContext", name, td, err)...).Log(ctx, w.opts.LoggerLevel) w.opts.Logger.Log(ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(ctx, "QueryContext", name, td, err)...)
} }
*/
return rows, err return rows, err
} }

24
tx.go
View File

@ -5,7 +5,7 @@ import (
"database/sql/driver" "database/sql/driver"
"time" "time"
"go.unistack.org/micro/v4/tracer" "go.unistack.org/micro/v3/tracer"
) )
var _ driver.Tx = (*wrapperTx)(nil) var _ driver.Tx = (*wrapperTx)(nil)
@ -23,19 +23,18 @@ func (w *wrapperTx) Commit() error {
ts := time.Now() ts := time.Now()
err := w.tx.Commit() err := w.tx.Commit()
td := time.Since(ts) td := time.Since(ts)
_ = td
if w.span != nil { if w.span != nil {
if err != nil { if err != nil {
w.span.AddLabels("error", true) w.span.SetStatus(tracer.SpanStatusError, err.Error())
w.span.AddLabels("err", err.Error())
} }
w.span.Finish() w.span.Finish()
} }
/*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(w.ctx, "Commit", labelUnknown, td, err)...).Log(w.ctx, w.opts.LoggerLevel) w.opts.Logger.Log(w.ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(w.ctx, "Commit", getCallerName(), td, err)...)
} }
*/
w.ctx = nil w.ctx = nil
return err return err
@ -46,19 +45,18 @@ func (w *wrapperTx) Rollback() error {
ts := time.Now() ts := time.Now()
err := w.tx.Rollback() err := w.tx.Rollback()
td := time.Since(ts) td := time.Since(ts)
_ = td
if w.span != nil { if w.span != nil {
if err != nil { if err != nil {
w.span.AddLabels("error", true) w.span.SetStatus(tracer.SpanStatusError, err.Error())
w.span.AddLabels("err", err.Error())
} }
w.span.Finish() w.span.Finish()
} }
/*
if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) { if w.opts.LoggerEnabled && w.opts.Logger.V(w.opts.LoggerLevel) {
w.opts.Logger.Fields(w.opts.LoggerObserver(w.ctx, "Rollback", labelUnknown, td, err)...).Log(w.ctx, w.opts.LoggerLevel) w.opts.Logger.Log(w.ctx, w.opts.LoggerLevel, w.opts.LoggerObserver(w.ctx, "Rollback", getCallerName(), td, err)...)
} }
*/
w.ctx = nil w.ctx = nil
return err return err

File diff suppressed because it is too large Load Diff