diff --git a/extra/redisotel/tracing.go b/extra/redisotel/tracing.go index 40df5a202..95f7031f2 100644 --- a/extra/redisotel/tracing.go +++ b/extra/redisotel/tracing.go @@ -21,7 +21,7 @@ const ( instrumName = "github.com/redis/go-redis/extra/redisotel" ) -func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error { +func InstrumentTracing(ctx context.Context, rdb redis.UniversalClient, opts ...TracingOption) error { switch rdb := rdb.(type) { case *redis.Client: opt := rdb.Options() @@ -36,6 +36,14 @@ func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error { connString := formatDBConnString(opt.Network, opt.Addr) rdb.AddHook(newTracingHook(connString, opts...)) }) + + rdb.ForEachShard(ctx, func(ctx context.Context, rdb *redis.Client) error { + opt := rdb.Options() + opts = addServerAttributes(opts, opt.Addr) + connString := formatDBConnString(opt.Network, opt.Addr) + rdb.AddHook(newTracingHook(connString, opts...)) + return nil + }) return nil case *redis.Ring: rdb.OnNewNode(func(rdb *redis.Client) { @@ -44,6 +52,14 @@ func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error { connString := formatDBConnString(opt.Network, opt.Addr) rdb.AddHook(newTracingHook(connString, opts...)) }) + + rdb.ForEachShard(ctx, func(ctx context.Context, rdb *redis.Client) error { + opt := rdb.Options() + opts = addServerAttributes(opts, opt.Addr) + connString := formatDBConnString(opt.Network, opt.Addr) + rdb.AddHook(newTracingHook(connString, opts...)) + return nil + }) return nil default: return fmt.Errorf("redisotel: %T not supported", rdb)