Compare commits

...

3 Commits

Author SHA1 Message Date
fa3d18b353 tracing commented redis.dial
Some checks failed
build / test (push) Failing after 21s
build / lint (push) Successful in 20s
codeql / analyze (go) (push) Failing after 39s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-07-18 11:28:45 +03:00
2f3951773f cleanup trace spans
Some checks failed
build / lint (push) Successful in 24s
build / test (push) Failing after 1m25s
codeql / analyze (go) (push) Failing after 1m53s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-07-05 23:11:12 +03:00
b263e14032 cleanup trace spans from cluster slots command
Some checks failed
build / lint (push) Successful in 22s
build / test (push) Failing after 1m30s
codeql / analyze (go) (push) Failing after 1m51s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-07-05 13:44:29 +03:00

View File

@@ -6,7 +6,7 @@ import (
"net" "net"
"strconv" "strconv"
"github.com/redis/go-redis/extra/rediscmd/v9" rediscmd "github.com/redis/go-redis/extra/rediscmd/v9"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"go.unistack.org/micro/v3/tracer" "go.unistack.org/micro/v3/tracer"
) )
@@ -18,14 +18,12 @@ func setTracing(rdb redis.UniversalClient, tr tracer.Tracer, opts ...tracer.Span
connString := formatDBConnString(opt.Network, opt.Addr) connString := formatDBConnString(opt.Network, opt.Addr)
rdb.AddHook(newTracingHook(connString, tr)) rdb.AddHook(newTracingHook(connString, tr))
case *redis.ClusterClient: case *redis.ClusterClient:
rdb.AddHook(newTracingHook("", tr, opts...))
rdb.OnNewNode(func(rdb *redis.Client) { rdb.OnNewNode(func(rdb *redis.Client) {
opt := rdb.Options() opt := rdb.Options()
connString := formatDBConnString(opt.Network, opt.Addr) connString := formatDBConnString(opt.Network, opt.Addr)
rdb.AddHook(newTracingHook(connString, tr)) rdb.AddHook(newTracingHook(connString, tr))
}) })
case *redis.Ring: case *redis.Ring:
rdb.AddHook(newTracingHook("", tr, opts...))
rdb.OnNewNode(func(rdb *redis.Client) { rdb.OnNewNode(func(rdb *redis.Client) {
opt := rdb.Options() opt := rdb.Options()
connString := formatDBConnString(opt.Network, opt.Addr) connString := formatDBConnString(opt.Network, opt.Addr)
@@ -55,11 +53,12 @@ func newTracingHook(connString string, tr tracer.Tracer, opts ...tracer.SpanOpti
func (h *tracingHook) DialHook(hook redis.DialHook) redis.DialHook { func (h *tracingHook) DialHook(hook redis.DialHook) redis.DialHook {
return func(ctx context.Context, network, addr string) (net.Conn, error) { return func(ctx context.Context, network, addr string) (net.Conn, error) {
/*
_, span := h.tr.Start(ctx, "redis.dial", h.opts...) _, span := h.tr.Start(ctx, "redis.dial", h.opts...)
defer span.Finish() defer span.Finish()
*/
conn, err := hook(ctx, network, addr) conn, err := hook(ctx, network, addr)
recordError(span, err) // recordError(span, err)
return conn, err return conn, err
} }
@@ -68,12 +67,20 @@ func (h *tracingHook) DialHook(hook redis.DialHook) redis.DialHook {
func (h *tracingHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook { func (h *tracingHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error { return func(ctx context.Context, cmd redis.Cmder) error {
cmdString := rediscmd.CmdString(cmd) cmdString := rediscmd.CmdString(cmd)
var err error
switch cmdString {
case "cluster slots":
break
default:
_, span := h.tr.Start(ctx, "redis.process", append(h.opts, tracer.WithSpanLabels("db.statement", cmdString))...) _, span := h.tr.Start(ctx, "redis.process", append(h.opts, tracer.WithSpanLabels("db.statement", cmdString))...)
defer span.Finish() defer func() {
err := hook(ctx, cmd)
recordError(span, err) recordError(span, err)
span.Finish()
}()
}
err = hook(ctx, cmd)
return err return err
} }