Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
fa3d18b353 | |||
2f3951773f | |||
b263e14032 |
23
tracer.go
23
tracer.go
@@ -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
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user